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