#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  long long sm = 0;
  vector<int> a(n), cnt(N);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
    sm += a[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    sm -= cnt[b] * b;
    sm += cnt[b] * c;
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sm << '\n';
  }
}
