#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  const int t = 100005;
  cin >> n;
  ll sum = 0;
  vector<int> a(t);
  for (int i = 0; i < (n); i++) {
    int l;
    cin >> l;
    a[l]++;
    sum += l;
  }
  cout << endl;
  int q;
  cin >> q;
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    sum -= b * a[b];
    sum += c * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
