#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

std::vector<int> Primes;

template <int toTest, int factor> // factor should be odd
class IsPrime
{
public:
enum {
result = ( toTest == 2 )
||  toTest % factor
&& IsPrime < toTest , factor - 2 >::result
};
};

template<int toTest>
class IsPrime<toTest, 1>
{
public:
enum {result = ( toTest == 2 )  || ( toTest & 1 ) };
};

template <int upperBound> // upperBound should be odd or 2
class PrimePick : public PrimePick < upperBound - 2 >
{
public:
enum {
isPrime = IsPrime < upperBound, ( upperBound >> 1 ) | 1 >::result
};
PrimePick<upperBound>() {
if ( isPrime )
Primes.push_back ( upperBound );
}
};

template<>
class PrimePick<2>
{
public:
PrimePick<2>() {
Primes.push_back ( 2 );
}
};

template<>
class PrimePick<1> : public PrimePick<2> {};

int main()
{
PrimePick<999> PrimeInitializer;

int m;
std::cin >> m;
for ( int i = 0; i < m; ++i ) {
int n;
std::cin >> n;

std::vector<int>::iterator end = Primes.begin();
while ( end != Primes.end() && *end <= n )
++end;

std::ostream_iterator<int> out ( std::cout, " " );
std::copy ( Primes.begin(), end, out );
std::cout << std::endl;
}
}


vijos果然被卡住了 – -