#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> make_pair;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    make_pair[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long x;
    cin >> x;
    long long y;
    cin >> y;
    sum = sum - x * make_pair[x] + make_pair[x] * y;
    cout << sum << endl;
    make_pair[y] += make_pair[x];
  }
}
