#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
long long int powD(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    x = (x * x);
    y = y >> 1;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  vector<int> cnt(1e5 + 1, 0);
  long long int sum = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    sum += x;
    cnt[x]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    sum -= cnt[b] * b;
    cnt[c] += cnt[b];
    sum += cnt[b] * c;
    cnt[b] = 0;
    cout << sum << "\n";
  }
}
