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