#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  long long int sum;
  cin >> n;
  int a[n];
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  while (q--) {
    int b1, c1;
    cin >> b1 >> c1;
    int value = m[b1];
    sum = sum - (b1 * value);
    sum = sum + (c1 * value);
    cout << sum << endl;
    m[c1] += value;
    m.erase(b1);
  }
  return 0;
}
