#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int n,q;
  cin >> n;
  int tmp;
  int a[1e5+7]={};

  int sum = 0;
  rep(i,n){
    cin >> tmp;
    sum += tmp;
    a[tmp]++;
  }

  cin >> q;
  int b,c;
  rep(i,q) {
    cin >> b >> c;
    if(a[b]>0){
      sum += (c-b)*a[b];
      a[c] += a[b];
      a[b] = 0;
    }
    cout << sum << endl;
  }
}