#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vs = vector<string>;
using pll = pair<long long, long long>;
int main() {
  long long n, q, ans = 0;
  cin >> n;
  vll a(100001, 0);
  for (long long(i) = 0; (i) < (n); (i)++) {
    int k;
    cin >> k;
    a.at(k)++;
    ans += k;
  }
  cin >> q;
  for (long long(i) = 0; (i) < (q); (i)++) {
    int b, c, k;
    cin >> b >> c;
    if (a.at(b) > 0) {
      k = a.at(b);
      a.at(c) += k;
      a.at(b) = 0;
      ans = ans + c * k - k * b;
    }
    cout << ans << endl;
  }
}
