how can i improve my time for the following code?
import java.io.*;
class LastDigit {
public static void main(String arg[])throws Exception
{
BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
String ip;
// System.out.println("enter the no. of test cases");
int a=Integer.parseInt(r.readLine());
// sc.nextLine();
int ipnos [][] = new int[a][2];
for(int i=0;i<a;i++)
{
// System.out.println("enter test cases");
ip=r.readLine();
String[] arr = ip.split("\\s+");
ipnos[i][0] = Integer.parseInt(arr[0]);
ipnos[i][1] = Integer.parseInt(arr[1]);
}
for(int i=0 ; i<a; i++)
{
System.out.println(sum1(ipnos[i][0],ipnos[i][1]));
}
}
static int sum1(int a, int b)
{
int sum=0,c=0,sumlast=0;
for(int i=a; i<=b;i++){
int m=i;
while(m!=0){
if( ((m%10)%2) ==0)
sum+=2*(m%10);
else
sum+=(m%10);
m/=10;
}
sumlast+= (sum%10);
sum=0;
}
return sumlast;
}
}