#include <bits/stdc++.h>
#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;

int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
  
vector<int> vector_fixer(vector<int> a,int target, int fixer){
  while(vector_finder(a, target)){
    vector<int>::iterator itr;
    itr = find(a.begin(), a.end(), target);
    int index = distance(a.begin(), itr);
    a[index] = fixer;
  }
  return a;
}

int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  int n;
  cin>>n;
  map<int, int> a;
  int sum = 0;
  int a;
  rep(i,n) {
    cin>>a;
    sum += a;
    mp[a]++;
  }
  int q;
  cin>>q;
  rep(i,q) {
    int b,c;
    cin>>b>>c;
    sum += (c-b)*mp[b]);
    cout << sum << endl;
    mp[c] += mp[b];
    mp[b] = 0;
  }
  return 0;
}