#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int num[n+5]={0};
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&num[i]);
    }
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int b,c;
        scanf("%d %d",&b,&c);
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            if(num[i]==b)num[i]=c;
            sum+=num[i];
        }
        printf("%d\n",sum);
    }
    return 0;
}
