#include <bits/stdc++.h>
using namespace std;
int main() {
  unordered_map<int, int> m;
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int temp = a[i];
    m[temp]++;
  }
  int ans = accumulate(a, a + n, 0);
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    cout << ans - (x * m[x]) + (y * m[x]) << endl;
    ans = ans - (x * m[x]) + (y * m[x]);
    m[y] += m[x];
    m[x] = 0;
  }
}
