#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
int n, i, ans, q, x, y, a[M], b[M];
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    ans += a[i];
    b[a[i]]++;
  }
  cin >> q;
  for (i = 1; i <= q; i++) {
    cin >> x >> y;
    ans += b[x] * (y - x);
    b[y] += b[x], b[x] = 0;
    cout << ans << endl;
  }
  return 0;
}
