#include<bits/stdc++.h>
using namespace std;
int main(){
long long int s1=0,s2=1;
string s;
int n;
while(cin>>n){
for(int i=0;i<n;i++){
int count=0;
cin>>s;
while(true){
s1=stoi(s);
reverse(s.begin(),s.end());
s2=stoi(s);
if(s1==s2&&count>0){break;}
else{
s=to_string(s1+s2);
count++;
}}
cout<<count<<" "<<s<<'\n';
}}}