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