import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedList;
 
class Solution {
 
    public static void main(String args[]) throws Exception {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        for (int T = 1; T <= 10; T++) {
 
            // [input] 데이터 입력
            int dataSize = Integer.parseInt(br.readLine());
            String[] originData = br.readLine().trim().split(" ");
            int commandSize = Integer.parseInt(br.readLine());
            String[] commandData = br.readLine().trim().split(" ");
 
            LinkedList<Integer> ticket = new LinkedList<>();
 
            for (int i = 0; i < originData.length; i++) {
                ticket.add(Integer.parseInt(originData[i]));
            }
 
            int cnt = 0;
            while (cnt < commandData.length) {
                String Command = commandData[cnt++];
                 
                int commandIndex = -1;
                if(!Command.equals("A")) {
                    commandIndex = Integer.parseInt(commandData[cnt++]);
                }
                 
                int Valuecount = Integer.parseInt(commandData[cnt++]);
 
                if(Command.equals("I")) {
                    int insertValue;
                    for (int j = 0; j < Valuecount; j++) {
                        insertValue = Integer.parseInt(commandData[cnt++]);
                        ticket.add(commandIndex++, insertValue);
                    }
                }else if(Command.equals("D")) {
                    for (int j = 0; j < Valuecount; j++) {
                        ticket.remove(commandIndex);
                    }
                }else {
                    int addValue;
                    for (int j = 0; j < Valuecount; j++) {
                        addValue = Integer.parseInt(commandData[cnt++]);
                        ticket.add(addValue);
                    }
                }
                 
            }
 
            String result = String.format("#%d", T);
            for (int i = 0; i < 10; i++) {
                result += String.format(" %d", ticket.get(i));
            }
             
            System.out.println(result);
        }
 
    }
 
}


+ Recent posts