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