import java.io.*;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
LinkedList<String> q = new LinkedList<>();
int n = Integer.parseInt(br.readLine());
while (n-- > 0) {
String line = br.readLine();
if (line.contains("push")) {
q.offer(line.split(" ")[1]);
} else if ("pop".equals(line)) {
System.out.println(q.isEmpty() ? -1 : q.poll());
} else if ("size".equals(line)) {
System.out.println(q.size());
} else if ("empty".equals(line)) {
System.out.println(q.isEmpty() ? 1 : 0);
} else if ("front".equals(line)) {
System.out.println(q.isEmpty() ? -1 : q.getFirst());
} else if ("back".equals(line)) {
System.out.println(q.isEmpty() ? -1 : q.getLast());
}
}
} catch (IOException e) {
System.out.println("err 😭 " + e.getCause());
}
}
}
히히 😊