#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, sum = 0;
  cin >> n;
  vector<int> v(n);
  unordered_map<int, int> m;
  for (int &i : v) {
    cin >> i;
    m[i]++;
    sum += i;
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; i++) {
    sum -= m[b[i]] * b[i];
    sum += m[b[i]] * c[i];
    m[c[i]] += m[b[i]];
    m[b[i]] = 0;
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
