#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  scanf("%d",&n);
  long long sum=0;
  int x;
  int c[100010];
  //unordered_map<int,int>m;
  memset(c,0,sizeof(c));
  for(i=0;i<n;i++)
  {
    scanf("%d",&x);
    c[x]++;
    sum+=x;
  }
  int q;
  scanf("%d",&q);
  while(q--)
  {
    int b,p;
    scanf("%d%d",&b,&p);
    sum-=b*c[b];
    c[p]+=c[b];
    sum+=p*c[b];
    c[b]=0;
    printf("%lld\n",sum);
  }
    
}