# your code goes here
import sys

def solve():
    # Fast I/O
    input = sys.stdin.read
    data = input().split()
    
    if not data:
        return

    # Parse N and the list of numbers
    N = int(data[0])
    numbers = [int(x) for x in data[1:N+1]]
    
    # Parse Q
    Q = int(data[N+1])
    
    # Step 1: Build the prefix sum array
    pref = [0] * N
    pref[0] = numbers[0]
    for k in range(1, N):
        pref[k] = pref[k-1] + numbers[k]
        
    # Step 2: Process each query
    # Queries start at index N + 2 in the flattened data array
    query_idx = N + 2
    output = []
    
    for _ in range(Q):
        i = int(data[query_idx])
        j = int(data[query_idx+1])
        query_idx += 2
        
        # Ensure i is the smaller index if they are given out of order
        if i > j:
            i, j = j, i
            
        # O(1) Range Sum Calculation
        if i == 0:
            output.append(str(pref[j]))
        else:
            output.append(str(pref[j] - pref[i-1]))
            
    # Print all answers separated by a newline
    sys.stdout.write('\n'.join(output) + '\n')

if __name__ == '__main__':
    solve()
