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