For an array $b$ of length $m$ we define the function $f$ as  $ f(b) = \begin{cases} b[1] & \quad \text{if } m = 1 \\ f(b[1] \oplus b[2],b[2] \oplus b[3],\dots,b[m-1] \oplus b[m]) & \quad \text{otherwise,} \end{cases} $ 

where $\oplus$ is bitwise exclusive OR.

For example, $f(1,2,4,8)=f(1\oplus2,2\oplus4,4\oplus8)=f(3,6,12)=f(3\oplus6,6\oplus12)=f(5,10)=f(5\oplus10)=f(15)=15$

You are given an array $a$ and a few queries. Each query is represented as two integers $l$ and $r$. The answer is the maximum value of $f$ on all continuous subsegments of the array $a_l, a_{l+1}, \ldots, a_r$.


-----Input-----

The first line contains a single integer $n$ ($1 \le n \le 5000$) — the length of $a$.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$) — the elements of the array.

The third line contains a single integer $q$ ($1 \le q \le 100\,000$) — the number of queries.

Each of the next $q$ lines contains a query represented as two integers $l$, $r$ ($1 \le l \le r \le n$).


-----Output-----

Print $q$ lines — the answers for the queries.


-----Examples-----
Input
3
8 4 1
2
2 3
1 2

Output
5
12

Input
6
1 2 4 8 16 32
4
1 6
2 5
3 4
1 2

Output
60
30
12
3



-----Note-----

In first sample in both queries the maximum value of the function is reached on the subsegment that is equal to the whole segment.

In second sample, optimal segment for first query are $[3,6]$, for second query — $[2,5]$, for third — $[3,4]$, for fourth — $[1,2]$.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Dynamic programming


Solutions:
t = 1
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	dp = [[0 for j in range(n)] for i in range(n)]
	for i in range(n):
		dp[0][i] = l[i]
	for i in range(1, n):
		for j in range(n - i):
			dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1]
	for i in range(1, n):
		for j in range(n - i):
			dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i - 1][j + 1])
	q = int(input())
	for __ in range(q):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		print(dp[y - x][x])


n = int(input())
arr = list(map(int, input().split()))
matrix = [[0] * n for _ in range(n)]
for i in range(n):
	matrix[0][i] = arr[i]
for i in range(1, n):
	for j in range(n - i):
		matrix[i][j] = matrix[i - 1][j] ^ matrix[i - 1][j + 1]
for i in range(1, n):
	for j in range(n - i):
		matrix[i][j] = max(matrix[i][j], matrix[i - 1][j], matrix[i - 1][j + 1])
queries = int(input())
responses = []
while queries > 0:
	(l, r) = list(map(int, input().split()))
	l -= 1
	r -= 1
	responses.append(matrix[r - l][l])
	queries -= 1
for response in responses:
	print(response)


n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
dp = [[0] * n for i in range(n)]
for i in range(n):
	dp[0][i] = a[i]
for i in range(1, n):
	for j in range(n - i):
		dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1]
for i in range(1, n):
	for j in range(n - i):
		dp[i][j] = max(max(dp[i][j], dp[i - 1][j]), dp[i - 1][j + 1])
for i in range(q):
	(l, r) = map(int, input().split())
	print(dp[r - l][l - 1])


import bisect
import os, sys, atexit, threading
from io import BytesIO, StringIO
from sys import stdin, stdout

def calculate(array):
	n = len(array)
	finalarray = []
	finalarray.append(array)
	finalarray.append([])
	while n != 1:
		for x in range(n - 1):
			finalarray[-1].append(finalarray[-2][x] ^ finalarray[-2][x + 1])
		finalarray.append([])
		n -= 1
	return finalarray

def solve():
	n = int(input())
	array = [0]
	array.extend(list(map(int, stdin.readline().strip().split())))
	subArrays = []
	for x in range(n + 1):
		subArrays.append([0] * (n + 1))
	finalarray = calculate(array)
	for x in range(1, n + 1):
		for y in range(x, n + 1):
			value = finalarray[y - x][x]
			subArrays[1][y] = max(subArrays[1][y], value)
			subArrays[x][y] = max(subArrays[x][y], value)
	for x in range(1, n + 1):
		for y in range(2, n + 1):
			subArrays[x][y] = max(subArrays[x][y], subArrays[x][y - 1])
	for y in range(1, n + 1):
		for x in range(n - 1, 0, -1):
			subArrays[x][y] = max(subArrays[x][y], subArrays[x + 1][y])
	q = int(input())
	for _ in range(q):
		(l, r) = map(int, stdin.readline().strip().split())
		print(subArrays[l][r])
try:
	solve()
except Exception as e:
	print(e)


def f(array, i, j):
	result = array[i + 1][j] ^ array[i][j - 1]
	array[i][j] = result
	return result
arrayLength = int(input())
textArray = input().split(' ')
queriesNum = int(input())
queries = []
for i in range(queriesNum):
	queries.append(input())
results = []
processed = []
for i in range(arrayLength):
	processed.append([-1] * arrayLength)
	results.append([-1] * arrayLength)
for i in range(arrayLength):
	num = int(textArray[i])
	processed[i][i] = num
	results[i][i] = num
i = 0
spacing = 1
while spacing < arrayLength:
	i = 0
	while i + spacing < arrayLength:
		j = i + spacing
		num1 = f(processed, i, j)
		num2 = results[i + 1][j]
		num3 = results[i][j - 1]
		results[i][j] = max(num1, num2, num3)
		i += 1
	spacing += 1
for i in queries:
	query = i.split(' ')
	queryA = int(query[0]) - 1
	queryB = int(query[1]) - 1
	print(results[queryA][queryB])


import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
dp = [[0] * n for i in range(n)]
for i in range(n):
	dp[i][i] = a[i]
count = 1
for i in range(n - 1):
	for j in range(n - i - 1):
		dp[j][j + count] = dp[j][j + count - 1] ^ dp[j + 1][j + count]
	count += 1
count = 1
for i in range(n - 1):
	for j in range(n - i - 1):
		dp[j][j + count] = max(dp[j][j + count], dp[j][j + count - 1], dp[j + 1][j + count])
	count += 1
for i in range(int(input())):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	print(dp[l][r])


from sys import stdin, stdout
n = int(input())
dp = [[-1 for i in range(n + 1)] for j in range(n + 1)]
dp[0] = list(map(int, stdin.readline().strip().split()))
for i in range(1, n):
	for j in range(n - i):
		dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1]
for i in range(1, n):
	for j in range(n - i):
		dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + 1], dp[i][j])
q = int(input())
for i in range(q):
	(l, r) = map(int, stdin.readline().strip().split())
	print(dp[r - l][l - 1])


n = int(input())
a = list(map(lambda x: int(x), input().split()))
b = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
	b[0][i] = a[i]
for i in range(1, n):
	for j in range(n - i):
		b[i][j] = b[i - 1][j] ^ b[i - 1][j + 1]
for i in range(1, n):
	for j in range(n - i):
		pp = max(b[i - 1][j], b[i - 1][j + 1])
		b[i][j] = max(b[i][j], pp)
q = int(input())
for i in range(q):
	(l, r) = input().split()
	l = int(l)
	r = int(r)
	print(b[r - l][l - 1])


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
l = list(map(int, input().split()))
dp = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
	dp[i][i] = l[i]
for i in range(n - 1, -1, -1):
	for j in range(i + 1, n):
		dp[i][j] = max(dp[i][j], dp[i][j - 1] ^ dp[i + 1][j])
for i in range(n - 1, -1, -1):
	for j in range(i + 1, n):
		dp[i][j] = max(dp[i][j], dp[i][j - 1], dp[i + 1][j])
for i in range(int(input())):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	print(dp[l][r])


import sys
n = int(input())
matriz = [[0] * n for i in range(n)]
maiores = matriz
entrada = list(map(int, sys.stdin.readline().split()))
for i in range(n):
	matriz[i][i] = entrada[i]
for i in range(n - 1, -1, -1):
	for j in range(i + 1, n):
		a = matriz[i][j - 1]
		b = matriz[i + 1][j]
		xor = a ^ b
		matriz[i][j] = xor
for i in range(n - 1, -1, -1):
	for j in range(i + 1, n):
		a = matriz[i][j - 1]
		b = matriz[i + 1][j]
		matriz[i][j] = max(matriz[i][j], a, b)
m = int(input())
for i in range(m):
	query = list(map(int, sys.stdin.readline().split()))
	print(matriz[query[0] - 1][query[1] - 1])


N = -1
PD = [[]]

def entrypoint():
	global N, PD
	N = int(input())
	PD = [[-1 for i in range(N + 1)] for j in range(N + 1)]
	PD[0] = list(map(int, input().split()))

def process():

	def compute_pd(ITER=0):
		compute_pd_lmbd = None
		if ITER == 0:
			compute_pd_lmbd = lambda i, j: PD[i - 1][j] ^ PD[i - 1][j + 1]
		elif ITER == 1:
			compute_pd_lmbd = lambda i, j: max(PD[i - 1][j], PD[i - 1][j + 1], PD[i][j])
		for i in range(1, N):
			for j in range(N - i):
				PD[i][j] = compute_pd_lmbd(i, j)
	compute_pd(0)
	compute_pd(1)
	Q = int(input())
	for _ in range(Q):
		(l, r) = map(int, input().split())
		print(PD[r - l][l - 1])

def main():
	entrypoint()
	process()
main()


tamanho = int(input())
elementos = list(map(int, input().split()))
matrix = [[0] * tamanho for i in range(tamanho)]
for i in range(tamanho):
	matrix[0][i] = elementos[i]
for i in range(1, tamanho):
	for j in range(tamanho - i):
		matrix[i][j] = matrix[i - 1][j] ^ matrix[i - 1][j + 1]
for i in range(1, tamanho):
	for j in range(tamanho - i):
		matrix[i][j] = max(matrix[i][j], matrix[i - 1][j], matrix[i - 1][j + 1])
num_buscas = int(input())
for i in range(num_buscas):
	(busca_l, busca_r) = map(int, input().split())
	(busca_l, busca_r) = (busca_l - 1, busca_r - 1)
	print(matrix[busca_r - busca_l][busca_l])


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
A = list(map(int, input().split()))
dp = [[0] * n for i in range(n)]
for i in range(n):
	dp[0][i] = A[i]
for i in range(1, n):
	for j in range(n - i):
		dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1]
for i in range(1, n):
	for j in range(n - i):
		dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i - 1][j + 1])
q = int(input())
for i in range(q):
	(l, r) = map(int, input().split())
	(l, r) = (l - 1, r - 1)
	print(dp[r - l][l])


import bisect
import os, sys, atexit, threading
from io import BytesIO, StringIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def calculate(array):
	n = len(array)
	finalarray = []
	finalarray.append(array)
	finalarray.append([])
	while n != 1:
		for x in range(n - 1):
			finalarray[-1].append(finalarray[-2][x] ^ finalarray[-2][x + 1])
		finalarray.append([])
		n -= 1
	return finalarray

def solve():
	n = int(input())
	array = [0]
	array.extend(list(map(int, input().split())))
	ranges = []
	q = int(input())
	for _ in range(q):
		(l, r) = map(int, input().split())
		ranges.append([l, r])
	subArrays = []
	for x in range(n + 1):
		subArrays.append([0] * (n + 1))
	finalarray = calculate(array)
	for x in range(1, n + 1):
		for y in range(x, n + 1):
			value = finalarray[y - x][x]
			subArrays[1][y] = max(subArrays[1][y], value)
			subArrays[x][y] = max(subArrays[x][y], value)
	for x in range(1, n + 1):
		for y in range(2, n + 1):
			subArrays[x][y] = max(subArrays[x][y], subArrays[x][y - 1])
	for y in range(1, n + 1):
		for x in range(n - 1, 0, -1):
			subArrays[x][y] = max(subArrays[x][y], subArrays[x + 1][y])
	for (l, r) in ranges:
		print(subArrays[l][r])
try:
	solve()
except Exception as e:
	print(e)


n = int(input())
A = list(map(int, input().split()))
dp = [[0] * n for i in range(n)]
for i in range(n):
	dp[0][i] = A[i]
for i in range(1, n):
	for j in range(n - i):
		dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1]
for i in range(1, n):
	for j in range(n - i):
		dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i - 1][j + 1])
q = int(input())
for i in range(q):
	(l, r) = map(int, input().split())
	(l, r) = (l - 1, r - 1)
	print(dp[r - l][l])


n = int(input())
matrix = [[0] * n for i in range(n)]
inpt = list(map(int, input().split()))
for i in range(n):
	matrix[i][i] = inpt[i]
for i in range(n - 1, -1, -1):
	for j in range(i + 1, n):
		a = matrix[i][j - 1]
		b = matrix[i + 1][j]
		xor = a ^ b
		matrix[i][j] = xor
for i in range(n - 1, -1, -1):
	for j in range(i + 1, n):
		a = matrix[i][j - 1]
		b = matrix[i + 1][j]
		matrix[i][j] = max(matrix[i][j], a, b)
m = int(input())
for i in range(m):
	query = list(map(int, input().split()))
	print(matrix[query[0] - 1][query[1] - 1])


import sys
from sys import stdin, stdout
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split(' ')))
dp = [list(arr)]
for i in range(n - 1):
	t1 = []
	for j in range(1, len(dp[-1])):
		t1.append(dp[-1][j - 1] ^ dp[-1][j])
	dp.append(t1)
for j in range(1, len(dp)):
	for k in range(len(dp[j])):
		dp[j][k] = max(dp[j][k], dp[j - 1][k], dp[j - 1][k + 1])
q = int(stdin.readline())
for _ in range(q):
	(l, r) = map(int, stdin.readline().split(' '))
	stdout.write(str(dp[r - l][l - 1]) + '\n')


n = int(input())
lista = [[-1 for i in range(n + 1)] for j in range(n + 1)]
lista[0] = list(map(int, input().split()))
q = int(input())
for i in range(1, n):
	for j in range(n - i):
		lista[i][j] = lista[i - 1][j] ^ lista[i - 1][j + 1]
for i in range(1, n):
	for j in range(n - i):
		lista[i][j] = max(lista[i - 1][j], lista[i - 1][j + 1], lista[i][j])
for i in range(q):
	val = input().split()
	print(lista[int(val[1]) - int(val[0])][int(val[0]) - 1])


def solution(n, As, q, query):
	ap = [[0 for j in range(0, n - i)] for i in range(0, n)]
	for i in range(0, n):
		ap[0][i] = As[i]
	for i in range(1, n):
		for j in range(0, n - i):
			ap[i][j] = ap[i - 1][j] ^ ap[i - 1][j + 1]
	for i in range(1, n):
		for j in range(0, n - i):
			ap[i][j] = max(max(ap[i][j], ap[i - 1][j]), ap[i - 1][j + 1])
	for i in range(0, q):
		print(ap[query[i][1] - query[i][0]][query[i][0] - 1])
n = int(input())
As = [int(a) for a in input().split()]
q = int(input())
query = [[int(a) for a in input().split()] for i in range(0, q)]
solution(n, As, q, query)


n = int(input())
values = list(map(int, input().split()))
queries = int(input())
dp = [[0] * 5009 for i in range(5009)]
for i in range(n):
	dp[0][i] = values[i]
for i in range(1, n):
	for j in range(n - i + 1):
		top = dp[i - 1][j]
		right = dp[i - 1][j + 1]
		dp[i][j] = top ^ right
for i in range(1, n):
	for j in range(n - i + 1):
		top = dp[i - 1][j]
		right = dp[i - 1][j + 1]
		dp[i][j] = max(right, max(dp[i][j], top))
for i in range(queries):
	(left, right) = map(int, input().split())
	last_row = right - 1 - (left - 1)
	last_column = left - 1
	print(dp[last_row][last_column])


n = int(input())
a = list(map(int, input().split(' ')))
array_a = [a]
for _ in range(n - 1):
	aux = []
	for i in range(1, len(array_a[-1])):
		aux.append(array_a[-1][i - 1] ^ array_a[-1][i])
	array_a.append(aux)
for i in range(1, len(array_a)):
	for j in range(len(array_a[i])):
		array_a[i][j] = max(array_a[i][j], array_a[i - 1][j], array_a[i - 1][j + 1])
k = int(input())
for _ in range(k):
	(l, r) = map(int, input().split(' '))
	print(str(array_a[r - l][l - 1]) + '\n')


n = int(input())
matriz = [int(x) for x in input().split()]
consultas = int(input())
b = [[int(x) for x in input().split()] for i in range(0, consultas)]
matriz_populada = [[0 for j in range(0, n - i)] for i in range(0, n)]
for i in range(0, n):
	matriz_populada[0][i] = matriz[i]
for i in range(1, n):
	for j in range(0, n - i):
		matriz_populada[i][j] = matriz_populada[i - 1][j] ^ matriz_populada[i - 1][j + 1]
for i in range(1, n):
	for j in range(0, n - i):
		matriz_populada[i][j] = max(max(matriz_populada[i][j], matriz_populada[i - 1][j]), matriz_populada[i - 1][j + 1])
for i in range(0, consultas):
	print(matriz_populada[b[i][1] - b[i][0]][b[i][0] - 1])


def xorPiramid(n, arrayAs, q, query):
	arrayAsPopulada = [[0 for j in range(0, n - i)] for i in range(0, n)]
	for i in range(0, n):
		arrayAsPopulada[0][i] = arrayAs[i]
	for i in range(1, n):
		for j in range(0, n - i):
			arrayAsPopulada[i][j] = arrayAsPopulada[i - 1][j] ^ arrayAsPopulada[i - 1][j + 1]
	for i in range(1, n):
		for j in range(0, n - i):
			arrayAsPopulada[i][j] = max(max(arrayAsPopulada[i][j], arrayAsPopulada[i - 1][j]), arrayAsPopulada[i - 1][j + 1])
	for i in range(0, q):
		print(arrayAsPopulada[query[i][1] - query[i][0]][query[i][0] - 1])
n = int(input())
arrayAs = [int(a) for a in input().split()]
q = int(input())
query = [[int(a) for a in input().split()] for i in range(0, q)]
xorPiramid(n, arrayAs, q, query)


import sys, os

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))
n = read_int()
a = read_ints()
dp = [[0] * n for _ in range(n)]
f = [[0] * n for _ in range(n)]
for i in range(n - 1, -1, -1):
	f[i][i] = dp[i][i] = a[i]
	for j in range(i + 1, n):
		f[i][j] = f[i][j - 1] ^ f[i + 1][j]
		dp[i][j] = max(f[i][j], dp[i][j - 1], dp[i + 1][j])
q = read_int()
for _ in range(q):
	(l, r) = read_ints()
	print(dp[l - 1][r - 1])


def pyramid_xor(array, size):
	pd = [[0] * (size + 1) for _ in range(size)]
	for n in range(size):
		pd[0][n] = array[n]
	for m in range(1, size):
		for n in range(size - m):
			pd[m][n] = pd[m - 1][n] ^ pd[m - 1][n + 1]
	for m in range(1, size):
		for n in range(size - m):
			pd[m][n] = max(pd[m][n], pd[m - 1][n], pd[m - 1][n + 1])
	return pd
n = int(input())
pd = pyramid_xor(list(map(int, input().split())), n)
queries = int(input())
for _ in range(queries):
	(l, r) = map(int, input().split())
	print(pd[r - l][l - 1])


from sys import stdin

def main():
	n = int(input())
	aa = list(map(int, input().split()))
	dp = [aa]
	for i in range(n - 1, 0, -1):
		aa = aa[:]
		for j in range(i):
			aa[j] ^= aa[j + 1]
		del aa[-1]
		dp.append(aa)
	aa = dp[0]
	for (i, bb) in enumerate(dp[1:], 1):
		a = aa[0]
		for (j, b) in enumerate(bb):
			c = aa[j + 1]
			bb[j] = max(a, b, c)
			a = c
		aa = bb
	input()
	res = stdin.read().splitlines()
	for (i, s) in enumerate(res):
		(lo, hi) = map(int, s.split())
		res[i] = str(dp[hi - lo][lo - 1])
	print('\n'.join(res))
main()


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
(*a,) = map(int, input().split())
dp = [[0 for i in range(n + 1)] for j in range(n + 1)]
for i in range(n):
	dp[0][i] = a[i]
for i in range(1, n):
	for j in range(n - i + 1):
		dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1]
for i in range(1, n):
	for j in range(n - i):
		dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i - 1][j + 1])
for i in range(int(input())):
	(l, r) = map(int, input().split())
	print(dp[r - l][l - 1])


n = int(input())
a = [int(x) for x in input().split()]
c = int(input())
b = [[int(x) for x in input().split()] for i in range(0, c)]
f = [[0 for j in range(0, n - i)] for i in range(0, n)]
for i in range(0, n):
	f[0][i] = a[i]
for i in range(1, n):
	for j in range(0, n - i):
		f[i][j] = f[i - 1][j] ^ f[i - 1][j + 1]
for i in range(1, n):
	for j in range(0, n - i):
		f[i][j] = max(max(f[i][j], f[i - 1][j]), f[i - 1][j + 1])
for i in range(0, c):
	print(f[b[i][1] - b[i][0]][b[i][0] - 1])


n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
vec = [[int(x) for x in input().split()] for i in range(0, q)]
ax = [[0 for j in range(0, n - i)] for i in range(0, n)]
for i in range(0, n):
	ax[0][i] = a[i]
for i in range(1, n):
	for j in range(0, n - i):
		ax[i][j] = ax[i - 1][j] ^ ax[i - 1][j + 1]
for i in range(1, n):
	for j in range(0, n - i):
		ax[i][j] = max(max(ax[i][j], ax[i - 1][j]), ax[i - 1][j + 1])
for i in range(0, q):
	print(ax[vec[i][1] - vec[i][0]][vec[i][0] - 1])


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
f = [[0] * n for i in range(n)]
for i in range(n):
	f[0][i] = a[i]
for i in range(1, n):
	for j in range(n - i):
		f[i][j] = f[i - 1][j] ^ f[i - 1][j + 1]
for i in range(1, n):
	for j in range(n - i):
		f[i][j] = max(f[i][j], f[i - 1][j], f[i - 1][j + 1])
q = int(input())
for _ in range(q):
	(l, r) = map(int, input().split())
	print(f[r - l][l - 1])


import sys
input = sys.stdin.readline
n = int(input())
ar = list(map(int, input().split()))
dic = {}
li = []
for i in range(n):
	xx = []
	for j in range(n - i):
		xx.append(0)
	li.append(xx.copy())
for i in range(n):
	for j in range(n - i):
		if i == 0:
			li[i][j] = ar[j]
		else:
			li[i][j] = li[i - 1][j] ^ li[i - 1][j + 1]
for i in range(1, n):
	for j in range(n - i):
		li[i][j] = max(li[i][j], li[i - 1][j], li[i - 1][j + 1])
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	print(li[r - l][l - 1])


def pyramid(arr, n):
	mtx = [[0] * n for _ in range(n)]
	for i in range(n):
		mtx[0][i] = arr[i]
	for i in range(1, n):
		for j in range(n - i):
			mtx[i][j] = mtx[i - 1][j] ^ mtx[i - 1][j + 1]
	for i in range(1, n):
		for j in range(n - i):
			mtx[i][j] = max(mtx[i][j], mtx[i - 1][j], mtx[i - 1][j + 1])
	q = int(input())
	for _ in range(q):
		(l, r) = list(map(int, input().split()))
		l -= 1
		r -= 1
		print(mtx[r - l][l])
n = int(input())
arr = list(map(int, input().split()))
pyramid(arr, n)


from sys import stdin, stdout
repetition = int(input())
s = list(map(int, stdin.readline().strip().split()))
number_common = 1
vector = [[-number_common for index in range(repetition + number_common)] for index_2 in range(repetition + number_common)]
for index in range(repetition):
	vector[0][index] = s[index]
for index in range(number_common, repetition):
	for index_2 in range(repetition - index):
		vector[index][index_2] = vector[index - number_common][index_2] ^ vector[index - number_common][index_2 + number_common]
for index in range(number_common, repetition):
	for index_2 in range(repetition - index):
		vector[index][index_2] = max(vector[index - number_common][index_2], vector[index - number_common][index_2 + number_common], vector[index][index_2])
for index in range(int(input())):
	(l, r) = map(int, stdin.readline().strip().split())
	print(vector[r - l][l - number_common])


import sys
import math
input = sys.stdin.readline
from functools import cmp_to_key

def pi():
	return int(input())

def pl():
	return int(input(), 16)

def ti():
	return list(map(int, input().split()))

def ts():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
mod = 998244353
f = []

def fact(n, m):
	global f
	f = [1 for i in range(n + 1)]
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % m

def fast_mod_exp(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b = b >> 1
	return res

def inverseMod(n, m):
	return fast_mod_exp(n, m - 2, m)

def ncr(n, r, m):
	if r == 0:
		return 1
	return f[n] * inverseMod(f[n - r], m) % m * inverseMod(f[r], m) % m

def main():
	B()
dp = []

def D():
	[n, k] = ti()
	a = ti()
	a = sorted(a)
	cnt = [0 for i in range(n)]
	for i in range(n):
		c = 0
		for j in range(i, n):
			if a[j] - a[i] <= 5:
				c += 1
			else:
				break
		cnt[i] = c
	global dp
	dp = [[0 for j in range(k + 1)] for i in range(n + 1)]
	ans = 0
	for i in range(n):
		for j in range(k + 1):
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
			if j + 1 <= k:
				dp[i + cnt[i]][j + 1] = max(dp[i + cnt[i]][j + 1], dp[i][j] + cnt[i])
	print(dp[n][k])

def B():
	n = pi()
	a = ti()
	q = pi()
	mat = [[0 for j in range(n)] for i in range(n)]
	dp = [[0 for i in range(n)] for j in range(n)]
	for i in range(n):
		for j in range(n):
			if i == j:
				mat[i][j] = a[i]
				dp[i][j] = a[i]
	i = 0
	x = 1
	while x < n:
		j = x
		i = 0
		while j < n:
			mat[i][j] = mat[i][j - 1] ^ mat[i + 1][j]
			j += 1
			i += 1
		x += 1
	i = 0
	x = 1
	while x < n:
		j = x
		i = 0
		while j < n:
			dp[i][j] = max(mat[i][j], dp[i][j - 1], dp[i + 1][j])
			j += 1
			i += 1
		x += 1
	for i in range(q):
		[l, r] = ti()
		print(dp[l - 1][r - 1])
main()


def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	array = []
	array.append(a)
	for i in range(n - 1):
		aux = []
		for j in range(1, len(array[-1])):
			xor = array[-1][j - 1] ^ array[-1][j]
			aux.append(xor)
		array.append(aux)
	for j in range(1, len(array)):
		for k in range(len(array[j])):
			maximo = max(array[j][k], array[j - 1][k], array[j - 1][k + 1])
			array[j][k] = maximo
	q = int(input())
	aux2 = []
	for i in range(q):
		(l, r) = map(int, input().split(' '))
		aux2.append((l, r))
	for i in aux2:
		(l, r) = (i[0], i[1])
		print(str(array[r - l][l - 1]))
main()


from sys import stdin, stdout
n = int(stdin.readline())
a = list(map(int, stdin.readline().split(' ')))
list_a = [a]
for _ in range(n - 1):
	temp = []
	for j in range(1, len(list_a[-1])):
		temp.append(list_a[-1][j - 1] ^ list_a[-1][j])
	list_a.append(temp)
for j in range(1, len(list_a)):
	for k in range(len(list_a[j])):
		list_a[j][k] = max(list_a[j][k], list_a[j - 1][k], list_a[j - 1][k + 1])
q = int(stdin.readline())
for _ in range(q):
	(l, r) = map(int, stdin.readline().split(' '))
	stdout.write(str(list_a[r - l][l - 1]) + '\n')


lenght = int(input())
elem = [int(x) for x in input().split()]
num = int(input())
vector = [[int(x) for x in input().split()] for i in range(0, num)]
aux = [[0 for j in range(0, lenght - i)] for i in range(0, lenght)]
for i in range(0, lenght):
	aux[0][i] = elem[i]
for i in range(1, lenght):
	for j in range(0, lenght - i):
		aux[i][j] = aux[i - 1][j] ^ aux[i - 1][j + 1]
for i in range(1, lenght):
	for j in range(0, lenght - i):
		aux[i][j] = max(max(aux[i][j], aux[i - 1][j]), aux[i - 1][j + 1])
for i in range(0, num):
	print(aux[vector[i][1] - vector[i][0]][vector[i][0] - 1])


n = int(input())
arr = list(map(int, input().split()))
aux = [[0] * n for i in range(n)]
for i in range(n):
	aux[0][i] = arr[i]
for i in range(1, n):
	for j in range(n - i):
		aux[i][j] = aux[i - 1][j] ^ aux[i - 1][j + 1]
for i in range(1, n):
	for j in range(n - i):
		aux[i][j] = max(aux[i][j], aux[i - 1][j], aux[i - 1][j + 1])
q = int(input())
for i in range(q):
	(buscaEsquerda, buscaDireita) = map(int, input().split())
	(buscaEsquerda, buscaDireita) = (buscaEsquerda - 1, buscaDireita - 1)
	print(aux[buscaDireita - buscaEsquerda][buscaEsquerda])


size = int(input())
a = list(map(int, input().split()))
s = int(input())
aux = [[0 for x in range(size + 1)] for y in range(size + 1)]
for i in range(size):
	aux[0][i] = a[i]
for i in range(1, size):
	for j in range(0, size - i + 1):
		aux[i][j] = aux[i - 1][j + 1] ^ aux[i - 1][j]
for i in range(1, size):
	for j in range(0, size - i):
		aux[i][j] = max(aux[i][j], aux[i - 1][j], aux[i - 1][j + 1])
for i in range(s):
	(l, r) = list(map(int, input().split()))
	l -= 1
	print(aux[r - l - 1][l])


n = int(input())
a = list(map(int, input().split(' ')))
list_a = [a]
for i in range(n - 1):
	temp = []
	for j in range(1, len(list_a[-1])):
		temp.append(list_a[-1][j - 1] ^ list_a[-1][j])
	list_a.append(temp)
for j in range(1, len(list_a)):
	for k in range(len(list_a[j])):
		list_a[j][k] = max(list_a[j][k], list_a[j - 1][k], list_a[j - 1][k + 1])
q = int(input())
for i in range(q):
	(l, r) = map(int, input().split(' '))
	print(str(list_a[r - l][l - 1]) + '\n')


number = int(input())
enter = list(map(int, input().split()))
xors = [[0 for x in range(number + 1)] for y in range(number + 1)]
for i in range(number):
	xors[0][i] = enter[i]
for i in range(1, number):
	for j in range(0, number - i + 1):
		xors[i][j] = xors[i - 1][j + 1] ^ xors[i - 1][j]
for i in range(1, number):
	for j in range(0, number - i):
		xors[i][j] = max(xors[i][j], xors[i - 1][j], xors[i - 1][j + 1])
q = int(input())
for i in range(q):
	(l, r) = list(map(int, input().split()))
	l -= 1
	print(xors[r - l - 1][l])