#include <bits/stdc++.h>
using namespace std;
struct pt {
  int x, y, num, val;
  bool operator<(const pt& p) const {
    if (y == p.y)
      return x < p.x;
    else
      return y < p.y;
  }
};
bool comp(pt& a, pt& b) {
  if (a.x == b.x)
    return a.y < b.y;
  else
    return a.x < b.x;
}
int main() {
  int n;
  cin >> n;
  multiset<int> s;
  unsigned long long sum = 0;
  multimap<int, int> mp;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    sum += x;
    s.insert(x);
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int a, b;
    cin >> a >> b;
    int cnt = s.count(a);
    sum = sum + cnt * (b - a);
    s.erase(a);
    while (cnt--) {
      s.insert(b);
    }
    cout << sum << '\n';
  }
  return 0;
}
