import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++)
{
int m = sc.nextInt();
int[] array = new int[m];
for (int j = 0; j < m; j++)
array[j] = sc.nextInt();
boolean stack = true, queue = true;
for (int j = 0; j < m; j++)
{
int num = sc.nextInt();
if (stack)
if (num != array[m - 1 - j])
stack = false;
if (queue)
if (num != array[j])
queue = false;
}
if (stack && queue)
System.out.println("both");
else if (stack)
System.out.println("stack");
else if (queue)
System.out.println("queue");
else
System.out.println("neither");
}
}
}
ZOJ-3210
最新推荐文章于 2018-08-17 19:12:51 发布