#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using ll = long long;
using namespace std;
void solve() {
  int n, q;
  cin >> n;
  map<int, int> m;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    m[x]++;
    sum += x;
  }
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    sum -= m[a] * a;
    sum += m[a] * b;
    m[b] += m[a];
    m[a] = 0;
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
