#include <bits/stdc++.h>
using namespace std;
struct mset {
  map<int, int> m;
  void remove(int x) {
    auto t = m.find(x);
    t->second--;
    if (t->second == 0) {
      m.erase(t);
    }
  }
  void add(int x) {
    auto t = m.find(x);
    if (t == m.end()) {
      m[x] = 1;
    } else {
      t->second++;
    }
  }
  bool empty() { return m.empty(); }
};
int main() {
  int n, q;
  cin >> n;
  mset m;
  long long s = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    m.add(a);
    s += a;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b;
    long long c;
    cin >> b >> c;
    auto p = m.m.find(b);
    if (p == m.m.end()) {
      cout << s << endl;
    } else {
      s = s + c * p->second - p->first * p->second;
      cout << s << endl;
      auto q = m.m.find(c);
      if (q == m.m.end()) {
        m.m[c] = p->second;
      } else {
        q->second += p->second;
      }
      m.m.erase(p);
    }
  }
}
