There are a few mistakes in the code, as @forthright48 mentioned.
In addition, your solution is a very complicated one. And, your solution takes much memory. It could be written in lesser codes.
I have written a simpler solution to this interesting problem -
for (int i = 0; i < T; i++)
scanf("%d", &p); //Testcase inputs
for (int j=1; j <= 10; j++)
printf("Case %d:\n", i);
printf("%d * %d = %d", p, j, (p*j));
You used many while loops. I have devised a much, better, easier, and efficient solution.