#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, q;
  vector<int> num(10005, 0);
  cin >> a;
  int sum = 0;
  for (int i = 0; i < a; i++) {
    int b;
    cin >> b;
    num[b]++;
    sum += b;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum -= b * num[b];
    sum += c * num[b];
    int d = num[b];
    num[b] = 0;
    num[c] += d;
    cout << sum << endl;
  }
}
