/*
博弈游戏
2到20的数,两个人轮流取
取数不能取之前已取过数的倍数,或之前取过的两个数的倍数之和
给出当前的一个合法局面,问先手要赢的策略
n<=20,比较明显的mask dp
dp[mask]表示剩下mask表示的数,当前下手是赢还是输
注意的是,多case,但是只算一次就行了,不用每个case都clear dp[]
因为知道了当前局面,就能确定之前选了什么数了
*/
#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<set>
#include<list>
#include<numeric>
#include<cassert>
#include<sstream>
#include<ctime>
#include<bitset>
#include<functional>
using namespace std;
char dp[1<<20];
void add(int &forbiden, int &multiple, int x)//forbiden为不能的位,multiple为之前选的那些数的倍数的位
{
for (int a = x; a <= 20 ; a += x) {
forbiden |= 1<<a;
multiple |= 1<<a;
forbiden |= multiple<<a;
}
}
bool win(int mask, int forbiden, int multiple, int x)
{
if (mask == 0) {
dp[mask] = -1;
return false;
}
if(dp[mask]) {
return dp[mask] > 0;
}
add(forbiden, multiple, x);
for (int i = 2; i <= 20; i++) {
if((mask & (1<<i-2)) == 0 || (forbiden&(1<<i)) )continue;
if (!win(mask ^ (1<<i-2), forbiden, multiple, i) ) {//这里提前退出了,有些子状态并没有算到
return dp[mask] = 1;
}
}
dp[mask] = -1;
return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in","r",stdin);
//freopen("out","w",stdout);
#endif
int T, t = 1, n;
for (scanf("%d", &T); T--; ) {
printf("Scenario #%d:\n", t++);
scanf("%d", &n);
vector<int> vt, have;
int vi[30] = {0}, mask = 0;
for (int i = 1,x; i <= n; i++) {
scanf("%d", &x);
vt.push_back(x);
vi[x] = 1;
mask |= 1<<(x-2);//
}
int forbiden = 0, multiple = 0;
for (int i = 2; i <= 20; i++) {//给出一个数,肯定给出他的所有因子
if (vi[i] || (forbiden & (1<<i)) ) continue;
add(forbiden, multiple, i);
}
// fill(dp, dp+mask+1, 0); 不用每次都clear
/*
不要搞一次win(mask)
然后取dp[mask ^ (1<<vt[i]-2),看win里面会提早退出的
所以有些dp[mask']没算到,会为0
不过取win(mask ^ (1<<vt[i]-2))就行吧
*/
vector<int> ans;
for (int i = 0; i < vt.size(); i++) {
if (!win(mask^(1<<vt[i]-2), forbiden, multiple, vt[i])) {
ans.push_back(vt[i]);
}
}
if(ans.empty()) {
puts("There is no winning move.");
} else {
printf("The winning moves are:");
sort(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); i++) {
printf(" %d", ans[i]);
}
puts(".");
}
puts("");
}
return 0;
}