Why this code not working for this test case?

problem: CodeChef: Practical coding for everyone

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    long int x,m,rev=0,last=0,mod=0,p=0;
	    cin>>x>>m;
	    while(x>0)
	    {
	        last=x%10;
	        p=pow(last,m);
	        mod=p%10;
	        rev=(rev*10)+mod;
	        x=x/10;
	    }
	    if(rev%7==0)cout<<"YES"<<'\n';
	    else cout<<"NO"<<'\n';
	}
	return 0;
}
//rev=pow((((rev*10)+last))%10,m);

above code working for some test cases but except one test case that is
1
9381827 99