import java.util.Scanner;publicclass 小型计算器 {staticlong num =0;staticint flag =-1;// 辅助运算staticint curRadix =10;// 辅助进制转换publicstaticvoidmain(String[] args){// TODO Auto-generated method stub
Scanner sc =newScanner(System.in);int n = sc.nextInt();
sc.nextLine();for(int i =0; i < n; i++){
String temp = sc.nextLine();f(temp);}}privatestaticvoidf(String temp){if(temp.length()==3)calculate(temp);elseif(temp.equals("CLEAR"))
num =0;elseif(temp.equals("EQUAL")){
System.out.println(Long.toString(num, curRadix).toUpperCase());}elseif(temp.split(" ")[0].equals("CHANGE"))change(temp.split(" ")[1]);elsecal(temp.split(" ")[1]);}privatestaticvoidcal(String string){
Long tempNum = Long.parseLong(string, curRadix);if(flag ==-1){
num = tempNum;}else{if(flag ==1)
num += tempNum;elseif(flag ==2)
num -= tempNum;elseif(flag ==3)
num *= tempNum;elseif(flag ==4)
num /= tempNum;else
num %= tempNum;
flag =-1;}}privatestaticvoidchange(String temp){
curRadix = Integer.parseInt(temp);}privatestaticvoidcalculate(String temp){if(temp.equals("ADD"))
flag =1;elseif(temp.equals("SUB"))
flag =2;elseif(temp.equals("MUL"))
flag =3;elseif(temp.equals("DIV"))
flag =4;else
flag =5;}}