#include <iostream>
using namespace std;
int buf[30];
int next(int n,int k){
if(!k)return 0;
long long k2=(long long)k*k;
int l=0;
int ans=0;
while(k2>0){
buf[l++]=k2%10;k2/=10;}
if (n>l)n=l;
for(int i=0;i<n;i++){
ans=ans*10+buf[l--];
}
return ans;
}
int main(){
int T;
cin>>T;
while(T--){
int n,k;
cin>>n>>k;
int ans=k,k1=k,k2=k;
do{
k1=next(n,k1);
k2=next(n,k2);if(k2>ans)ans=k2;
k2=next(n,k2);if(k2>ans)ans=k2;
}while(k1!=k2);
cout<<ans<<endl;
}
return 0;
}
uva 11549
最新推荐文章于 2019-12-18 20:06:00 发布