#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int a[n];
for(int i=0;i<n;i++)
{
cin >> a[i];
}
int q,x,y;
cin >> q;
while(q--)
{
cin >> x >> y;
for(int i=0;i<n;i++)
{
if(a[i]==x)
{
a[i]=y;
}
sum+=a[i];
}
cout << sum << endl;
}
return 0;
}