#include <bits/stdc++.h>
using namespace std;
int n, q, b, c, r, a[100005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> q;
    r += q;
    a[q]++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    r += (c - b) * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << r << "\n";
  }
  return 0;
}
