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