#include <stdio.h>
int main()
{
int t, n, N, sum, count;
scanf("%d", &t);
for (int i=0; i<t; i++)
{
scanf("%d", &n);
for (int a=1; a<=n; a++)
{
if (a%7 == 0)
{
printf("%d", a);
printf(" ");
}
else
{
int j = a;
while (j>1)
{
if ((j%10) == 7)
{
printf("%d", a);
printf(" ");
break;
}
else
j = j/10;
}
}
}
printf("\n");
}
return 0;
}