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