#include <cstdio>
#include <iostream>
using namespace std;

int main()
{
  int n, s;

  scanf("%d", &n);
  for (int i = 0; i < n; i++){
    scanf("%d", &s);
    printf("Case %d:\n", i + 1);
    for (int j = 0; j < 10; j++){
      printf("%d\n", s = s * s / 100 % 10000);
    }
  }

  return (0);
}