#include <bits/stdc++.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;
int main() {
  lll ii, jj, kk;
  vector<int> ret;
  lll n;
  cin >> n;
  vector<lll> a(n);
  for (ii = 0; ii < n; ii++) {
    cin >> a[ii];
  }
  lll q;
  cin >> q;
  lll b, c;
  lll sum;
  for (ii = 0; ii < q; ii++) {
    cin >> b >> c;
    sum = 0;
    for (jj = 0; jj < n; jj++) {
      if (a[jj] == b) {
        a[jj] = c;
      }
      sum += a[jj];
    }
    cout << sum << endl;
  }
  return 0;
}
