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