#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, k, q, p, b;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  while (q--) {
    cin >> p >> b;
    long long sum = 0;
    for (i = 0; i < n; i++) {
      if (a[i] == p) a[i] = b;
      sum += a[i];
    }
    cout << sum << endl;
  }
}
