#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int x, i, cnt = 0, j;
  cin >> x;
  int a[x];
  (i, a,
   cout << "No\n"
        << endl) for (i = a; i < cout << "No\n"
                                      << endl;
                      i++)(i, 0, x) cin >>
      a[i];
  int q, k, l, p;
  cin >> q;
  while (q--) {
    cnt = 0;
    cin >> k >> l;
    (i, a,
     cout << "No\n"
          << endl) for (i = a; i < cout << "No\n"
                                        << endl;
                        i++)(p, 0, x) if (a[p] == k) {
      a[p] = l;
    }
    (i, a,
     cout << "No\n"
          << endl) for (i = a; i < cout << "No\n"
                                        << endl;
                        i++)(j, 0, x) cnt += a[j];
    cout << cnt << endl;
  }
}
