#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXS = 1 << 20;
const int MAXN = 25;
int num[MAXN]; //可选的数
int win[MAXS]; //必胜的状态
//改变状态,根据数字x改变状态s
int changeState(int s, int x)
{
for (int i = x; i <= 20; i = i + x) //将x的倍数全部置为不可用
{
if (s & (1 << (i - 2)))
s = s & (~(1 << (i - 2)));
}
for (int i = 2; i <= 20; i++)
{
if (s & (1 << (i - 2)))
{
for (int j = x; i - j >= 2; j = j + x)
{
if (!(s & (1 << (i - j - 2))))
{
s = s & (~(1 << (i - 2)));
break;
}
}
}
}
return s;
}
int getSG(int s)
{
if (win[s] != -1)
return win[s];
int ans = 0;
for (int i = 2; i <= 20; i++)
{
if (s & (1 << (i - 2))) //i存在
{
int k = changeState(s, i);
if (!getSG(k))
return win[s] = 1;
}
}
return win[s] = 0;
}
int main()
{
int T;
cin >> T;
for (int Case = 1; Case <= T; Case++)
{
memset(win, -1, sizeof(win));
int n;
cin >> n;
int state = 0; //可选的数,状态压缩
for (int i = 0; i < n; i++)
{
cin >> num[i];
state |= (1 << (num[i] - 2));
}
sort(num, num + n);
cout << "Scenario #" << Case << ":" << endl;
if (!getSG(state))
cout << "There is no winning move." << endl;
else
{
cout << "The winning moves are:";
for (int i = 0; i < n; i++)
{
int s = changeState(state, num[i]);
if (!getSG(s))
cout << " " << num[i];
}
cout << "." << endl;
}
cout << endl;
}
return 0;
}