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