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