#!/bin/python import sys def initialize(s): # This function is called once before all queries. return def answerQuery(l, r): # Return the answer for this query modulo 1000000007. return (l+r)/2 if __name__ == "__main__": s = raw_input().strip() initialize(s) q = int(raw_input().strip()) for a0 in xrange(q): l, r = raw_input().strip().split(' ') l, r = [int(l), int(r)] result = answerQuery(l, r) print result