#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 66;
int a[maxn], b[maxn], vis[maxn], tmpp, tmp[maxn], alen, blen;
bool Print, tied;
void dfs(int maxkind, int minnum, int maxmoney, int x, int pre)
{
if (minnum > 4) return ;
if (x == tmpp)
{
if (maxkind > tmp[alen + 1])
{
tied = false;
for (int i = 1; i <= alen; i ++) tmp[i] = vis[i];
tmp[alen + 1] = maxkind;
tmp[alen + 2] = minnum;
tmp[alen + 3] = maxmoney;
}
else if (maxkind == tmp[alen + 1])
{
if (minnum < tmp[alen + 2])
{
for (int i = 1; i <= alen; i ++) tmp[i] = vis[i];
tmp[alen + 2] = minnum;
tmp[alen + 3] = maxmoney;
tied = false;
}
else if (minnum == tmp[alen + 2])
{
if (maxmoney > tmp[alen + 3])
{
for (int i = 1; i <= alen; i ++) tmp[i] = vis[i];
tmp[alen + 3] = maxmoney;
tied = false;
}
else if (maxmoney == tmp[alen + 3]) tied = true;
}
}
}
int temp;
for (int i = pre; i <= alen; i ++)
{
if (vis[i] < 4)
{
if (vis[i] == 0) maxkind ++;
vis[i] ++;
if (maxmoney <= a[i])
{
maxmoney = a[i];
temp = maxmoney;
}
dfs(maxkind, minnum + 1, maxmoney, x + a[i], i);
vis[i] --;
if (vis[i] == 0)
{
maxkind --;
if (a[i] == maxmoney) a[i] = temp;
}
}
}
}
signed main()
{
scanf("%d", &a[1]);
start:
tied = false;
for (int i = 2; ; i ++)
{
scanf("%d", &a[i]);
if (a[i] == 0)
{
alen = i - 1; break;
}
}
sort(a + 1, a + 1 + alen);
for (int i = 1; ; i ++)
{
scanf("%d", &b[i]);
if (b[i] == 0)
{
blen = i - 1; break;
}
}
for (int i = 1; i <= blen; i ++)
{
tied = Print = false;
tmp[alen + 2] = 0x3f3f3f3f;
memset(vis, 0, sizeof (vis));
memset(tmp, 0, sizeof (tmp));
tmpp = b[i];
dfs(0, 0, 0, 0, 1);
if (tied) printf("%d (%d): tie\n", tmpp, tmp[alen + 1]);
else
{
for (int i = 1; i <= alen; i ++)
{
if (tmp[i]) Print = true;
}
if (!Print) printf("%d ---- none\n", tmpp);
else
{
printf("%d (%d): ", tmpp, tmp[alen + 1]);
for (int i = 1; i <= alen; i ++)
{
for (int j = 1; j <= tmp[i]; j ++)
{
if (i == alen && j == tmp[i]) printf("%d", a[i]);
else printf("%d ", a[i]);
}
}
puts("");
}
}
}
if (~scanf("%d", &a[1])) goto start;
return 0;
}