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