#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n], i;
  for (i = 0; i < n; i++) cin >> a[i];
  long long int q;
  cin >> q;
  while (q--) {
    long long int b, c, sum;
    cin >> b >> c;
    sum = 0;
    for (i = 0; i < n; i++) {
      if (a[i] == b) {
        a[i] = c;
        sum = sum + c;
      } else {
        sum = sum + a[i];
      }
    }
    cout << sum << "\n";
  }
}
