#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
const long long MOD = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  multiset<long long> s;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    s.insert(x);
    sum += x;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long a, b;
    cin >> a >> b;
    while (s.find(a) != s.end()) {
      s.erase(s.find(a));
      s.insert(b);
      sum += b - a;
    }
    cout << sum << "\n";
  }
}
