#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char get(int x)//将x转换为字符形式
{
if (x <= 9) return x + '0';
return x - 10 + 'A';
}
string base(int n, int b)//将n转换为b进制,返回对应字符串
{
string res;
while (n)
{
res += get(n % b);
n /= b;
}
reverse(res.begin(), res.end());//翻转回高位在左
return res;
}
bool check(string s)//检查s是否是回文
{
for (int i = 0, j = s.size() - 1; i < j; i ++, j -- )
if (s[i] != s[j])
return false;
return true;
}
int main()
{
int b;
cin >> b;
for (int i = 1; i <= 300; i ++ )//暴力
{
string num = base(i * i, b);
if (check(num))
cout << base(i, b) << ' ' << num << endl;
}
return 0;
}