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