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