#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], sum = 0;
  std::map<int, int> m;
  auto it = m.begin();
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    it = m.find(a[i]);
    if (it != m.end())
      (*it).second++;
    else
      m[(a[i])] = 1;
  }
  int g, b, c;
  cin >> g;
  for (int i = 0; i < g; i++) {
    cin >> b >> c;
    it = m.find(b);
    if (it != m.end() && (*it).second != 0) {
      auto it2 = m.find(c);
      if (it2 == m.end())
        m[c] = (*it).second;
      else
        m[c] += (*it).second;
      sum += ((*it).second * (c - b));
      (*it).second = 0;
    }
    cout << sum << endl;
  }
}
