#include <stdio.h>
#include <string.h>
/*
hanio函数:表示当前的任务是将大小为floor的盘子从from移动到to,当然这个盘子如果在mid(另外一个柱子)上时就证明这不是最优序列,
如果在from上时就可以推出大小为floor-1的盘子的任务是从from移动到mid,如果floor在to上时则floor-1的任务是从mid移动到to上
*/
int h[3][64], tail[3], head[3];
bool hanio(int floor, int from, int to, int mid)
{
if(floor == 0)
return true;
int at=-1;
for(int i=0; i<3; i++)
if(h[i][ head[i] ] == floor)
{
at = i;
break;
}
if(at == -1 || at == mid)//如果没有大小为floor的盘子,或者这个盘子在mid柱子上,则不是最优序列
return false;
head[ at ] ++;
if(at == from)
hanio(floor-1, from, mid, to);
else if(at == to)
hanio(floor-1, mid, to, from);
}
int main()
{
int t, n;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
memset(tail, 0, sizeof(tail));
memset(head, 0, sizeof(head));
for(int i=0; i<3; i++)
{
scanf("%d", &tail[i]);
for(int j=0; j<tail[i]; j++)
scanf("%d", &h[i][j]);
}
printf(hanio(n, 0, 2, 1)?"true\n":"false\n");
}
return 0;
}