#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[100010];
  int q, b, c;
  int ans;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    ans = 0;
    for (int m = 1; m <= n; m++) {
      if (a[m] == b) {
        a[m] = c;
      }
    }
    for (int m = 1; m <= n; m++) {
      ans += a[m];
    }
    cout << ans << endl;
  }
  return 0;
}
