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