#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, arr[100000], q, sum, b1, c1, i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  cin >> q;
  while (q--) {
    cin >> b1 >> c1;
    sum = 0;
    for (i = 0; i < n; i++) {
      if (arr[i] == b1) {
        arr[i] = c1;
      }
      sum += arr[i];
    }
    cout << sum << endl;
  }
  return 0;
}
