#include <bits/stdc++.h>
using namespace std;
int main() {
  uint64_t n;
  cin >> n;
  vector<int> a(100001, 0);
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    a[m]++;
  }
  uint64_t sum = 0;
  for (int i = 1; i < a.size(); i++) {
    sum += i * a[i];
  }
  int q;
  cin >> q;
  vector<int> result(q);
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int m = a[b];
    a[b] = 0;
    a[c] += m;
    sum += (c - b) * m;
    result[i] = sum;
  }
  for (int i = 0; i < q; i++) {
    cout << result[i] << endl;
  }
  return 0;
}
