#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> m;
  long long int n;
  cin >> n;
  long long int a[n];
  long long int sum = 0;
  long long int neww = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    sum = sum + a[i];
  }
  sort(a, a + n);
  int q;
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; i++) {
    if (m[b[i]] != 0) {
      m[c[i]] = m[c[i]] + m[b[i]];
      sum = sum - m[b[i]] * b[i];
      sum = sum + m[b[i]] * c[i];
      m[b[i]] = 0;
    }
    cout << sum << endl;
  }
}
