#include <bits/stdc++.h>
using namespace std;
int sum = 0;
int arr[100000];
void findFirstAndLast(int arr[], int n, int b, int c) {
  int first = -1, last = -1;
  for (int i = 0; i < n; i++) {
    if (b != arr[i]) continue;
    if (first == -1) first = i;
    last = i;
  }
  if (first != -1) {
    int multiplier = last - first + 1;
    sum = sum - (multiplier * b) + (multiplier * c);
    for (int i = first; i <= last; i++) {
      arr[i] = c;
    }
  }
  cout << sum << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  int q;
  cin >> q;
  sort(arr, arr + n);
  while (q--) {
    int b, c;
    cin >> b >> c;
    findFirstAndLast(arr, n, b, c);
  }
  return 0;
}
