#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;

void random(int s) {
  for(int i=0;i<10;i++) {
    stringstream ss;string str;
    s *= s;
    ss << s;
    ss >> str;
    int aftsize = str.size();
    if(aftsize <= 2) {
      s = 0;
    }
    else if(aftsize <= 6) {
      s = atoi(str.substr(0,aftsize-2).c_str());
    }
    else if(aftsize > 6) {
      s = atoi(str.substr(aftsize-6,4).c_str());
    }
    cout << s << endl;
  }
}

int main() {
  int n,s;
  cin >> n;
  for(int i=0;i<n;i++) {
    cin >> s;
    cout << "Case " << i+1 << ":" << endl;
    random(s);
  }
}