#include <bits/stdc++.h>
int quick_sort(int a[], int start, int end, int data_size) {
  int pivot, temp = 0, i, j;
  pivot = end;
  temp = a[start];
  a[start] = a[pivot];
  a[pivot] = temp;
  i = start + 1;
  j = end;
  do {
    while (a[i] <= a[start] && i < end) i++;
    while (a[j] >= a[start] && j > start) j--;
    if (i < j) {
      temp = a[i];
      a[i] = a[j];
      a[j] = temp;
    }
  } while (i < j);
  temp = a[start];
  a[start] = a[j];
  a[j] = temp;
  if (start < j) quick_sort(a, start, j - 1, data_size);
  if (i < end) quick_sort(a, i, end, data_size);
}
int main() {
  int n, i, q, j, b, c, out = 0;
  scanf("%d", &n);
  int a[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    out = out + a[i];
  }
  quick_sort(a, 0, n - 1, n);
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    int time = 0;
    scanf("%d %d", &b, &c);
    if (a[0] > b || a[n - 1] < b)
      out = out;
    else {
      for (j = 0;; j++) {
        if (a[j] == b) {
          a[j] = c;
          time++;
        } else if (a[j] > b)
          break;
      }
      out = out + (c - b) * time;
    }
    printf("%d\n", out);
    quick_sort(a, 0, n - 1, n);
  }
  return 0;
}
