n = gets.to_i c = gets.chomp.delete(' ') q = gets.to_i for i in 1 .. q do t, *p = gets.split x, y = p.map(&:to_i).map{|n| n - 1} if t == "!" then c[y], c[x] = c[x], c[y] else puts (eval c[x .. y]) end end