It works fine for all the tests I have done myself. But on submission it gives a WA. Please explain what's wrong
#include<iostream>
#include<math.h>
using namespace std;
int main(){
long num, power, res;
long a, b, c;
int t;
cin>>t;
while(t){
cin>>num>>power;
b=power%4;
a=num%10;
c=pow(a,b);
res=c%10;
cout<<res<<"\n";
t--;
}
return 0;
}