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 fxy = (eval c[x .. y]) % 1000000007 puts fxy end end