#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ull  unsigned long long
#define ll long long int
#define ull unsigned long long 
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend() //reverse
#define vl vector< long long>v(n);
#define mii unordered_map<ll,ll>
double pi = 2*acos(0.0);
//ll power(ll a,ll b){ ll res=1;while(b){if(b&1)res=res*a;b=b/2; a=(a*a); }return res;}

 int main()
 {
       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
       ll tst;
       tst=1;
       //cin>>tst;
    
       while(tst--)
       {
          ll n;
          cin>>n;ull sum=0;
          vl(n);long long int count[n]={0};
          for(int i=0;i<n;i++)
          {
                          cin>>v[i];
                          sum+=v[i];
                          count[v[i]]++;
          }
          unsigned long long q;
          cin>>q;
          while(q--)
          {
             ll a,b;
             cin>>a>>b;
             sum-=count[a]*a;
             sum+=count[a]*b;
             count[b]+=count[a];
             count[a]=0;
             cout<<sum<<endl;
          }
        
        }
 }