public static void main (String args[]) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(reader.readLine());

		int currentOperation;
		int currentNumber;
		boolean isQueue;
		StringTokenizer st;
		for (int i=0; i<t; i++) {
			isQueue = true;
			int n = Integer.parseInt(reader.readLine());

			//LinkStack stack = new LinkStack();
			ArrayStack stack = new ArrayStack();

			for (int j=0; j<n; j++) {
				st = new StringTokenizer(reader.readLine());
				if (isQueue) {
					currentOperation = Integer.parseInt(st.nextToken());
					currentNumber = Integer.parseInt(st.nextToken());
					if (currentOperation == 1) {
						stack.enQueue(currentNumber);
					} else {
						isQueue = stack.deQueue(currentNumber);
					}
				}
			}

			System.out.println(isQueue ? "Queue" : "Stack");
		}
	}