Sir, here is the qustion:-

Nestor was doing the work of his math class about three days but he is tired of make operations a lot and he should deliver his task tomorrow. His mathâ€™s teacher gives two numbers a and b. The problem consist in find the last digit of the potency of base a and index b. Help Nestor with his problem. You are given two integer numbers: the base a (0 <= a <= 20) and the index b (0 <= b <= 2,147,483,000). You have to find the last digit of a^b.

**Input**

The first line of input contains an integer t, the number of test cases (t <= 30). t test cases follow. For each test case will appear a and b separated by space.

**Output**

For each test case output an integer per line representing the result.

Time limit: 1s

Source limit: 700B

Here is my code sir.

```
#include<stdio.h>
#include<math.h>
int fun(int,int);
int main()
{
int a,mod,nb,t,i;
unsigned long b;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d %lu",&a,&b);
if(a!=0 || b!=0)
{
mod=a%10;
if(mod==2 || mod==3 || mod==7 ||mod==8)
{
nb=b%4;
if(nb==0) nb=4;
if(b==0) nb=0;
fun(mod,nb);
}
else if(mod==4 || mod==9)
{
nb=b%2;
if(nb==0) nb=2;
if(b==0) nb=0;
fun(mod,nb);
}
else if(mod==0 || mod==1 || mod==5 || mod==6)
{
if(b==0) nb=0;
else nb=1;
fun(mod,nb);
}
}
}
return 0;
}
int fun(int mod,int nb)
{
int p,ld;
p=pow(mod,nb);
ld=p%10;
printf("%d\n",ld);
}
```

There is some error, due to which I am getting wrong answer. I have debugged the code lot of times and unable to find the reason of getting wrong answer.

Please help me sir.