/*
ID: aznfy1
PROG: palsquare
LANG: C++
*/
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int num[20];
int len;int flag;
void change(int x,int b)
{
int i=0;
while(x!=0)
{
num[i]=(x%b);
x=x/b;
i++;
}
len=i;
}
int main()
{
freopen("palsquare.in","r",stdin);
freopen("palsquare.out","w",stdout);
int n;
while(cin>>n)
{
for(int i=1;i<=300;i++)
{
flag=1;
change(i*i,n);
for(int i=0;i<len/2;i++)
{
if(num[len-i-1]!=num[i])
{
flag=0;
break;
}
}
if(flag)
{
change(i,n);
for(int i=len-1;i>=0;i--)
{
if(num[i]==10)
{cout<<'A';continue;}
if(num[i]==11)
{cout<<'B';continue;}
if(num[i]==12)
{cout<<'C';continue;}
if(num[i]==13)
{cout<<'D';continue;}
if(num[i]==14)
{cout<<'E';continue;}
if(num[i]==15)
{cout<<'F';continue;}
if(num[i]==16)
{cout<<'G';continue;}
if(num[i]==17)
{cout<<'H';continue;}
if(num[i]==18)
{cout<<'I';continue;}
if(num[i]==19)
{cout<<'J';continue;}
cout<<num[i];
}
cout<<' ';
change(i*i,n);
for(int i=0;i<len;i++)
{
if(num[i]==10)
{cout<<'A';continue;}
if(num[i]==11)
{cout<<'B';continue;}
if(num[i]==12)
{cout<<'C';continue;}
if(num[i]==13)
{cout<<'D';continue;}
if(num[i]==14)
{cout<<'E';continue;}
if(num[i]==15)
{cout<<'F';continue;}
if(num[i]==16)
{cout<<'G';continue;}
if(num[i]==17)
{cout<<'H';continue;}
if(num[i]==18)
{cout<<'I';continue;}
if(num[i]==19)
{cout<<'J';continue;}
cout<<num[i];
}
cout<<endl;
}
}
}
return 0;
}