# include <iostream>
# include <cstdio>
# include <queue>
using namespace std;
unsigned long long Input;
int main(int argc, char const *argv[])
{
    //freopen ("370_ONEZERO_input.txt",  "r", stdin);
	//freopen ("370_ONEZERO_output.txt", "w", stdout);
	int N;
	cin >> N;
	//scanf ("%d", &N);
	unsigned long long current = 0;
	queue <unsigned long long> Queue;
	for (int i = 0; i < N; i++)
	{

		cin >> Input;
		//scanf ("%d", &Input);
		//if (Input == 1) {printf ("1\n"); continue;} //cout << "1" << endl; continue;}
		//if (Input == 1) {cout << "1" << endl; continue;}
		Queue.push (11ULL); Queue.push (18ULL);
		while (!Queue.empty())
		{
			current = Queue.front();
			Queue.pop();
			if (current % Input)
			{
				Queue.push (current * 10ULL + 1ULL);
				Queue.push ((current * 10ULL) + 8ULL);
			}
			else
			{
				cout << current << endl;
				//printf ("%d\n", current);
				while (!Queue.empty()) Queue.pop();
			}
		}
	}
	return 0;
}