#include<iostream>
#include<vector>
using namespace std;
int main()
{
  long int n,q,i=0,l,r,s=0,p;
  cin>>n;
  vector<int> V(n),Z(100001,0);
  for(i=0;i<n;i++)
  {
    cin>>V[i];
    ++Z[V[i]];
    s+=V[i];
  }
  cin>>q;
  while(q--)
  {
    cin>>l>>r;
    p=Z[l];
    Z[r]+=p;
    Z[l]=0;
    s+=p*(r-l);
    cout<<s<<endl;
}
}