#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  multiset<long long int> s;
  for (int i = 0; i < n; i++) s.insert(a[i]);
  long long int q;
  cin >> q;
  long long int b, c, sum = 0;
  for (int i = 0; i < n; i++) sum += a[i];
  while (q--) {
    cin >> b >> c;
    sum -= (s.count(b) * b);
    sum += (s.count(b) * c);
    for (int i = 1; i <= s.count(b); i++) s.insert(c);
    s.erase(b);
    cout << sum << endl;
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
