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

public class java_av {

	FastScanner in;
	PrintWriter out;

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

		Map<String, MyList> arrays = new HashMap<>();
		
		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();

				String source = st.nextToken();
				if (source.equals("new")) {
					st.nextToken(); // List
					
					List<Integer> result = new ArrayList<>();
					while (st.hasMoreElements()) {
						result.add(Integer.parseInt(st.nextToken()));
					}
					arrays.put(name, new MyList(result));
					
				} else {
					st.nextToken(); // subList
					int from = Integer.parseInt(st.nextToken()) - 1, to = Integer.parseInt(st.nextToken()) - 1;
					arrays.put(name, new MyList(arrays.get(source), from));
				}
			} else {
				String name = token;
				MyList array = arrays.get(name);
				
				String op = st.nextToken();
				
				if (op.equals("set")) {
					int pos = Integer.parseInt(st.nextToken()) - 1;
					int val = Integer.parseInt(st.nextToken());
					array.set(pos, val);
				} else if (op.equals("add")) {
					int val = Integer.parseInt(st.nextToken());
					array.add(val);
				} else if (op.equals("get")) {
					int pos = Integer.parseInt(st.nextToken()) - 1;
					out.println(array.get(pos));
				}
			}
		}
	}
	
	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().run();
	}
}
