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