#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int q, b, c;
  cin >> q;
  long long int sum = 0;
  while (q--) {
    cin >> b >> c;
    long long int low = 0, high = n - 1;
    long long int mid = (low + high) / 2;
    if (a[mid] == b) {
      a[mid] = c;
    } else if (a[mid] > b) {
      low = 0;
      high = mid;
      for (int i = high - 1; i > low; i--) {
        if (a[i] == b) {
          a[i] = c;
        }
      }
    } else if (a[mid] <= b) {
      low = mid;
      high = n - 1;
      for (int i = mid; i <= high; i++) {
        if (a[i] == b) {
          a[i] = c;
        }
      }
    }
    for (long long int j = 0; j < n; j++) {
      sum = sum + a[j];
    }
    cout << sum << "\n";
    sum = 0;
  }
}
