#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    m[a[i]]++;
  }
  int q;
  cin >> q;
  long long sum = accumulate(a, a + n, 0);
  while (q--) {
    int b, c;
    cin >> b >> c;
    int k = m[b];
    sum -= (b * k);
    m.erase(b);
    m[c] += k;
    sum += (c * k);
    cout << sum << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
