#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, sum = 0;
  cin >> n;
  unordered_map<long long int, long long int> m;
  for (int i = 1; i <= n; i++) {
    long long int x;
    cin >> x;
    sum += x;
    m[x]++;
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    long long int x, y;
    cin >> x >> y;
    if (m.find(x) != m.end()) {
      long long int temp = m[x];
      sum += temp * (y - x);
      m[y] += temp;
    }
    cout << sum << " ";
  }
}
