#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  map<int, int> m;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    sum += a[i];
  }
  int q, c, d;
  cin >> q;
  int count = 0;
  for (int i = 0; i < q; i++) {
    cin >> c >> d;
    count = m[c];
    m[c] = 0;
    m[d] += count;
    sum = sum + (d - c) * count;
    cout << sum << endl;
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
