代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
// 请在此输入您的代码
int t;
long long int x;
char p[200005];
int xmod[15];
scanf("%d",&t);
for(int i=0;i<t;i++){
scanf("%lld%s",&x,p);
int index=x%10;
xmod[0]=index;
int k=1;
int temp=-1;
while(xmod[0]!=temp){
temp=index*x%10;
xmod[k]=temp;
index=temp;
k++;
}
k--;
int rest=0;
for(int i=0;i<strlen(p);i++){
rest=p[i]-'0'+rest*10;
if(rest>=k){
rest=rest%k;
}
}
if(rest!=0)
printf("%d\n",xmod[rest-1]);
else
printf("%d\n",xmod[k-1]);
}
return 0;
}