def Replacing():

    Num = list(map(int,input().split()))

    value_A = list(map(int,input().split()))

    NumB = int(input())

    for i in range(NumB):
        value_B = list(map(int,input().split()))

        value_A = [value_B[1] if j == value_B[0] else j for j in value_A]

        print(sum(value_A))

if __name__ == '__main__':
    Replacing()
