import java.io.*;
import java.util.*;

public class java_av_with_asserts {

	FastScanner in;
	PrintWriter out;

	final int MAX_A = 1_000_000_000;
	final int MAX_N = 100_000;

	void solve() throws IOException {
		int n = in.nextInt();

		if (n < 1 || n > MAX_N) {
			throw new AssertionError();
		}

		Map<String, MyList> arrays = new HashMap<>();
		int sumLengths = 0;

		for (int i = 0; i < n; i++) {
			String line = in.br.readLine();
			StringTokenizer st = new StringTokenizer(line, " .(),=");

			String token = st.nextToken();

			if (token.equals("List")) {
				String name = st.nextToken();

				if (name.length() > 10 || isBad(name)) {
					throw new AssertionError();
				}

				String source = st.nextToken();
				if (source.equals("new")) {
					st.nextToken(); // List

					List<Integer> result = new ArrayList<>();
					while (st.hasMoreElements()) {
						int newVal = Integer.parseInt(st.nextToken());
						if (newVal < 1 || newVal > MAX_A) {
							throw new AssertionError();
						}
						result.add(newVal);
					}
					sumLengths += result.size();
					arrays.put(name, new MyList(result));

				} else {
					st.nextToken(); // subList
					int from = Integer.parseInt(st.nextToken()) - 1, to = Integer
							.parseInt(st.nextToken()) - 1;
					if (from > to) {
						throw new AssertionError();
					}
					arrays.put(name, new MyList(arrays.get(source), from));
				}
			} else {
				String name = token;

				MyList array = arrays.get(name);
				if (array == null) {
					throw new AssertionError();
				}

				String op = st.nextToken();

				if (op.equals("set")) {
					int pos = Integer.parseInt(st.nextToken()) - 1;
					int val = Integer.parseInt(st.nextToken());
					if (val < 1 || val > MAX_A) {
						throw new AssertionError();
					}
					array.set(pos, val);
				} else if (op.equals("add")) {
					int val = Integer.parseInt(st.nextToken());
					if (val < 1 || val > MAX_A) {
						throw new AssertionError();
					}
					array.add(val);
				} else if (op.equals("get")) {
					int pos = Integer.parseInt(st.nextToken()) - 1;
					out.println(array.get(pos));
				}
			}
		}
		if (sumLengths > 100_000) {
			throw new AssertionError(sumLengths);
		}
	}

	private boolean isBad(String name) {
		return name.equals("list") || name.equals("new") || name.equals("get") || name.equals("set") || name.equals("add");
	}

	class MyList {
		List<Integer> source;
		int offset;

		public MyList(List<Integer> source) {
			this.source = source;
		}

		public MyList(MyList other, int offset) {
			this.source = other.source;
			this.offset = other.offset + offset;
		}

		public int get(int pos) {
			return source.get(offset + pos);
		}

		public void add(int val) {
			source.add(val);
		}

		public void set(int pos, int val) {
			source.set(pos + offset, val);
		}
	}

	void run() {
		try {
			in = new FastScanner("java.in");
			out = new PrintWriter("java.out");
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine(), " .()=");
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new java_av_with_asserts().run();
	}
}
