/*
ID: fniksic001
PROG: palsquare
LANG: C++
*/

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

string reverse(const string &s) {
    if (s.empty())
	return s;
    string r;
    for (int i = s.size() - 1; i >= 0; --i)
	r.push_back(s[i]);
    return r;
}

string represent(int n, int b) {
    string r;
    while (n) {
	if (n%b<10)
	    r.push_back(static_cast<char>(n%b)+'0');
	else
	    r.push_back(static_cast<char>(n%b-10)+'A');
	n/=b;
    }
    return r;
}

int main() {
    ifstream in("palsquare.in");
    ofstream out("palsquare.out");

    int B;
    in >> B;

    cout << represent(1, 10) << endl;
    cout << represent(10, 2) << endl;
    cout << reverse(represent(10, 2)) << endl;
    cout << reverse(represent(162, 16)) << endl;

    for (int i = 1; i <= 300; ++i) {
	string r(represent(i*i, B));
	if (r==reverse(r))
	    out << reverse(represent(i, B)) << " " << r << endl;
    }

    return 0;
}

