#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  map<int, int> a;
  int64_t sum_a = 0;
  for (auto i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a[tmp]++;
    sum_a += tmp;
  }
  cin >> q;
  for (auto i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum_a = sum_a - a[b] * b + a[b] * c;
    a[c] += a[b];
    a[b] = 0;
    cout << sum_a << endl;
  }
  return 0;
}
