#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  int A[n];
  int C[100000];
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    C[A[i]]++;
    ans += A[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int count;
    count = C[b];
    if (C[c] == C[b]) {
      C[c]++;
    } else {
      C[c] = C[b];
    }
    C[b] = 0;
    ans = ans - count * b + count * c;
    cout << ans << endl;
  }
  return 0;
}
