X = gets.chomp.to_i
K = gets.chomp.to_i
r = gets.chomp.split(' ').map(&:to_i)
Q = gets.chomp.to_i
query = []
Q.times do
  query << gets.chomp.split(' ').map(&:to_i)
end

query.each do |q|
  last = q[1]
  prevR = 0
  r.each.with_index(1) do |rk, index|
    s = index % 2 == 0 ? 1 : -1
    if q[0] <= rk
      last = [[last + s*(q[0] - prevR), 0].max, X].min
      break
    else
      last = [[last + s*(rk - prevR), 0].max, X].min
      prevR = rk
      if index >= r.length
        last = h(last + s*(-1)*(q[0] - prevR), 0, X)
      end
    end
  end
  p last
end