#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
class BigInt;
vector<BigInt*> World;
void WorldEnd()
{
int Z=World.size();
for (int i=0; i<Z; i++)
{
delete World[i];
}
World.clear();
}
class BigInt
{
public:
vector<int> Me;
BigInt();
BigInt(int inn);
BigInt(vector<int> inn);
BigInt reverse();
BigInt* add(BigInt* that);
void print();
bool isLoop();
//~BigInt();
BigInt& operator=(const BigInt&);
};
ostream& operator<<(ostream& os, const BigInt& object)
{
for(int i=object.Me.size()-1; i>=0 ; i--)
{
os<<object.Me[i];
}
return os;
}
BigInt& BigInt::operator =(const BigInt& rhs)
{
Me.clear();
for (int i=0; i<rhs.Me.size(); i++)
{
Me.push_back(rhs.Me[i]);
}
return *this;
}
bool BigInt::isLoop()
{
if (Me.size()==1)
return true;
if (Me.size()>=2)
{
if (Me.size()%2==0)
{
for (int i=0; i<= Me.size()/2 ; i++)
{
if (Me[i]!= Me[ Me.size()-1-i])
return false;
}
return true;
}else
{
for (int i=0; i<=(Me.size()-1)/2; i++)
{
if (Me[i]!= Me[ Me.size()-1-i])
return false;
}
return true;
}
}
return false;
}
BigInt* BigInt::add(BigInt* that)
{
vector<int> dest;
int carry=0;
for(int i=0; i<that->Me.size(); i++)
{
int sum= Me[i] + that->Me[i]+carry;
if (sum>=10)
{
carry=1; dest.push_back( sum-10);
}else {
carry=0; dest.push_back( sum);
}
}
if (carry==1)
dest.push_back(1);
BigInt* ret=new BigInt(dest);
World.push_back(ret);
return ret;
}
BigInt operator+(const BigInt& lhs,const BigInt& rhs)
{
// BigInt* ret= (&lhs)->add(&rhs);
// return (*ret);
//////////////////////////////////////
vector<int> dest;
int carry=0;
for(int i=0; i<lhs.Me.size(); i++)
{
int sum= lhs.Me[i] + rhs.Me[i]+carry;
if (sum>=10)
{
carry=1; dest.push_back( sum-10);
}else {
carry=0; dest.push_back( sum);
}
}
if (carry==1)
dest.push_back(1);
BigInt ret(dest);
return (ret);
}
BigInt BigInt::reverse()
{
vector<int> hand;
for (int i=Me.size()-1; i>=0; i--)
hand.push_back(Me[i]);
BigInt ret(hand);
return ret;
}
BigInt::BigInt(int inn)
{
while(inn>=10)
{
Me.push_back(inn%10);
inn /=10;
}
Me.push_back(inn);
}
BigInt::BigInt(vector<int> inn)
{
for (int i=0; i<inn.size(); i++)
{
Me.push_back(inn[i]);
}
}
BigInt::BigInt(){}
void BigInt::print()
{
for (int i=Me.size()-1; i>=0; i--)
{
cout<< Me[i];
}
}
void ACM10018(int P)
{
BigInt P1(P);
BigInt P2;
BigInt P3;
int Step=0;
do
{ P2=P1.reverse();
P3=P1+P2;
Step+=1;
if (!P3.isLoop())
P1=P3;
else
break;
}while(true);
cout<< Step<<" "<<(P3)<<endl;
}
int main()
{
int P,N;
cin>>N;
if (N>0 && N<=100)
{
for (int i=0; i<N; i++)
{
cin>>P;
ACM10018(P);
WorldEnd();
}
}
return 0;
}