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