#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using PP = pair<int, pair<int, int>>;
using T = tuple<string, int, int>;
const string EMP = " ";
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<ull> a(n + 1);
  ull ans = 0;
  for (int i = 0; i < (n); i++) {
    int aa;
    cin >> aa;
    ans += aa;
    a[aa]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    ans -= b * a[b];
    ans += c * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << ans << endl;
  }
  return 0;
}
