#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long double pi = acos(-1.0);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  int ans = 0;
  map<int, int> ma;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ans += a[i];
    ma[a[i]] += 1;
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
    ans += (c[i] - b[i]) * ma[b[i]];
    ma[c[i]] += ma[b[i]];
    ma[b[i]] = 0;
    cout << ans << endl;
  }
}
