#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(int inn);
	BigInt(vector<int> inn);
	BigInt* reverse();
	BigInt* add(BigInt* that);
	void print();
	bool isLoop();
	//~BigInt();
};
bool BigInt::isLoop()
{
	if (Me.size()==1)
		return true;
	else 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* BigInt::reverse()
{
	vector<int> hand;
	for (int i=Me.size()-1; i>=0; i--)
		hand.push_back(Me[i]);
	BigInt* ret= new BigInt(hand);
	World.push_back(ret);
	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]);
	}

}
void BigInt::print()
{
	for (int i=Me.size()-1; i>=0; i--)
	{
		cout<< Me[i];
	}	
}

void ACM10018(int P)
{	
	
	BigInt* P1=new BigInt(P);	
	BigInt* P2;
	BigInt* P3;
	World.push_back(P1);
	int Step=0;
	do
	{ P2=P1->reverse();
	  P3=P1->add(P2);
	  Step+=1;
	  if (!P3->isLoop())
	  	P1=P3;
	  else
	  	break;
	}while(true);
	cout<< Step<<" ";
	P3->print();
	cout<<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;
}
