#include <bits/stdc++.h>
using namespace std;
void solve() {
  vector<int> ar(1e5 + 1, 0);
  int n;
  scanf("%d", &n);
  ;
  vector<int> v(n);
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &v[i]);
    ;
    sum += v[i];
    ar[v[i]]++;
  }
  int q;
  scanf("%d", &q);
  ;
  for (int i = 0; i < q; ++i) {
    int b, c;
    scanf("%d", &b);
    ;
    scanf("%d", &c);
    ;
    if (ar[b]) {
      sum += (c - b) * ar[b];
      ar[c] += ar[b];
      ar[b] = 0;
    }
    cout << sum << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
