You've got an array *a*, consisting of *n* integers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>. You are allowed to perform two operations on this array:
 1.  Calculate the sum of current array elements on the segment [*l*, *r*], that is, count value *a*<sub class="lower-index">*l*</sub> + *a*<sub class="lower-index">*l* + 1</sub> + ... + *a*<sub class="lower-index">*r*</sub>. 1.  Apply the xor operation with a given number *x* to each array element on the segment [*l*, *r*], that is, execute <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/2ef04d094daf2dcff9a998a558bd9cab93bbd012.png" style="max-width: 100.0%;max-height: 100.0%;"/>. This operation changes exactly *r* - *l* + 1 array elements. 
Expression <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b364f2e04c665b78b924ec10666327a4ef4635bc.png" style="max-width: 100.0%;max-height: 100.0%;"/> means applying bitwise xor operation to numbers *x* and *y*. The given operation exists in all modern programming languages, for example in language C++ and Java it is marked as "^", in Pascal — as "xor".

You've got a list of *m* operations of the indicated type. Your task is to perform all given operations, for each sum query you should print the result you get.
The first line contains integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>) — the size of the array. The second line contains space-separated integers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (0 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">6</sup>) — the original array.

The third line contains integer *m* (1 ≤ *m* ≤ 5·10<sup class="upper-index">4</sup>) — the number of operations with the array. The *i*-th of the following *m* lines first contains an integer *t*<sub class="lower-index">*i*</sub> (1 ≤ *t*<sub class="lower-index">*i*</sub> ≤ 2) — the type of the *i*-th query. If *t*<sub class="lower-index">*i*</sub> = 1, then this is the query of the sum, if *t*<sub class="lower-index">*i*</sub> = 2, then this is the query to change array elements. If the *i*-th operation is of type 1, then next follow two integers *l*<sub class="lower-index">*i*</sub>, *r*<sub class="lower-index">*i*</sub> (1 ≤ *l*<sub class="lower-index">*i*</sub> ≤ *r*<sub class="lower-index">*i*</sub> ≤ *n*). If the *i*-th operation is of type 2, then next follow three integers *l*<sub class="lower-index">*i*</sub>, *r*<sub class="lower-index">*i*</sub>, *x*<sub class="lower-index">*i*</sub> (1 ≤ *l*<sub class="lower-index">*i*</sub> ≤ *r*<sub class="lower-index">*i*</sub> ≤ *n*, 1 ≤ *x*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">6</sup>). The numbers on the lines are separated by single spaces.
from io import BytesIO, IOBase
import sys
import os

# import time
import bisect
# import functools
import math
import random
# import re
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import cmp_to_key, lru_cache, reduce
from heapq import heapify, heappop, heappush, heappushpop, nlargest, nsmallest
from itertools import accumulate, combinations, permutations, count
from operator import add, iand, ior, itemgetter, mul, xor
from string import ascii_lowercase, ascii_uppercase
from typing import *

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")

BUFSIZE = 5096

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 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)

    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()


sys.stdin = IOWrapper(sys.stdin)
sys.stdout = IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def I():
    return input()

def II():
    return int(input())

def MII():
    return map(int, input().split())

def LI():
    return list(input().split())

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

def GMI():
    return map(lambda x: int(x) - 1, input().split())

def LGMI():
    return list(map(lambda x: int(x) - 1, input().split()))

inf = float('inf')

# from types import GeneratorType

# def bootstrap(f, stack=[]):
#     def wrappedfunc(*args, **kwargs):
#         if stack:
#             return f(*args, **kwargs)
#         else:
#             to = f(*args, **kwargs)
#             while True:
#                 if type(to) is GeneratorType:
#                     stack.append(to)
#                     to = next(to)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     to = stack[-1].send(to)
#             return to
#     return wrappedfunc

# RANDOM = random.getrandbits(32)

# class Wrapper(int):
#     def __init__(self, x):
#         int.__init__(x)

#     def __hash__(self):
#         return super(Wrapper, self).__hash__() ^ RANDOM

class LazySegmentTree:
    def __init__(self, nums):
        self.n = len(nums)
        self.nums = nums
        self.ones = [0] * (4 * self.n)
        self.lazy = [True] * (4 * self.n)
        self._build(0, 0, self.n-1)
 
    def _build(self, tree_index, l, r):
        if l == r:
            self.ones[tree_index] = self.nums[l]
            return
        left, right = 2 * tree_index + 1, 2 * tree_index + 2
        mid = (l + r) // 2
        self._build(left, l, mid)
        self._build(right, mid+1, r)
        self.ones[tree_index] = self.ones[left] + self.ones[right]
 
    def update(self, ql, qr):
        self._update(0, 0, self.n-1, ql, qr)
 
    def _update(self, tree_index, l, r, ql, qr):
        if l == ql and r == qr:
            self.lazy[tree_index] = not self.lazy[tree_index]
            ones = self.ones[tree_index]
            zeros = r - l + 1 - ones
            self.ones[tree_index] = zeros
            return
        left, right = 2 * tree_index + 1, 2 * tree_index + 2
        mid = (l + r) // 2
        if not self.lazy[tree_index]:
            self._update(left, l, mid, l, mid)
            self._update(right, mid+1, r, mid+1, r)
            self.lazy[tree_index] = True
        if qr <= mid: self._update(left, l, mid, ql, qr)
        elif ql > mid: self._update(right, mid+1, r, ql, qr)
        else:
            self._update(left, l, mid, ql, mid)
            self._update(right, mid+1, r, mid+1, qr)
        self.ones[tree_index] = self.ones[left] + self.ones[right]
 
    def query(self, ql, qr):
        return self._query(0, 0, self.n-1, ql, qr)
 
    def _query(self, tree_index, l, r, ql, qr):
        if l == ql and r == qr:
            return self.ones[tree_index]
        left, right = 2 * tree_index + 1, 2 * tree_index + 2
        mid = (l + r) // 2
        if not self.lazy[tree_index]:
            self._update(left, l, mid, l, mid)
            self._update(right, mid+1, r, mid+1, r)
            self.lazy[tree_index] = True
        if qr <= mid: return self._query(left, l, mid, ql, qr)
        if ql > mid: return self._query(right, mid+1, r, ql, qr)
        ones1 = self._query(left, l, mid, ql, mid)
        ones2 = self._query(right, mid+1, r, mid+1, qr)
        return ones1 + ones2
n = II()
nums = LII()
q = II()
queries = [LII() for _ in range(q)]

ans = [0] * sum(2 - x[0] for x in queries)
for bit in range(20):
    tmp = 1 << bit
    seg = LazySegmentTree([1 if x >> bit & 1 else 0 for x in nums])
    pt = 0
    for query in queries:
        if query[0] == 1:
            ans[pt] += tmp * seg.query(query[1] - 1, query[2] - 1)
            pt += 1
        elif query[-1] >> bit & 1:
            seg.update(query[1] - 1, query[2] - 1)
print(*ans, sep='\n')