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