#include <bits/stdc++.h>
using namespace std;
vector<int> d(100010);
int main() {
  int n, q, a, b, c, ans;
  cin >> n;
  ans = 0;
  for (int i = 0; i < (n); i++) {
    cin >> a;
    d[a]++;
    ans += a;
  }
  cin >> q;
  for (int i = 1; i < (q + 1); i++) {
    cin >> b >> c;
    ans -= d[b] * b;
    ans -= d[c] * c;
    d[c] += d[b];
    d[b] = 0;
    ans += d[c] * c;
    cout << ans << endl;
  }
}
