#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, l = 100010;
  cin >> n;
  vector<int> a(n), cnt(l);
  for (int i = 0; i < (n); i++) cin >> a[i];
  cin >> q;
  vector<pair<int, int>> m(q);
  for (int i = 0; i < (q); i++) cin >> m[i].first >> m[i].second;
  int sum = 0;
  for (int i = 0; i < (n); i++) {
    sum += a[i];
    cnt[a[i]]++;
  }
  int b, c;
  for (int i = 0; i < (q); i++) {
    b = m[i].first;
    c = m[i].second;
    sum += cnt[b] * (c - b);
    cout << sum << endl;
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
  return 0;
}
