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