#include <bits/stdc++.h>
char num_debug = 0;
int compare_int(const void* a, const void* b) { return *(int*)a - *(int*)b; }
int nibun(int Array[], int n, int target) {
  int l = 0;
  int r = n;
  int p = (l + r) / 2;
  while (l <= r) {
    if (Array[p] < target)
      l = p + 1;
    else if (target < Array[p])
      r = p - 1;
    else
      break;
    p = (l + r) / 2;
  }
  if (r < l) return -1;
  r = p;
  if (p != 0) {
    while (l < r) {
      p = (r + l) / 2;
      if (Array[p] == target)
        r = p;
      else
        l = p + 1;
    }
  }
  p = r;
  return p;
}
int main(void) {
  srand((unsigned)time(NULL));
  int N, *A, Q, *B, *C;
  scanf("%d", &N);
  A = (int*)calloc(N, sizeof(int));
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  scanf("%d", &Q);
  B = (int*)calloc(Q, sizeof(int));
  C = (int*)calloc(Q, sizeof(int));
  for (int i = 0; i < Q; i++) scanf("%d%d", &B[i], &C[i]);
  for (int i = 0; i < Q; i++) {
    int p;
    qsort(A, N, sizeof(int), compare_int);
    p = nibun(A, N, B[i]);
    if (p != -1)
      while (A[p] == B[i]) {
        A[p] = C[i];
        p++;
        ;
      }
    unsigned long int sum = 0;
    for (int i = 0; i < N; i++) {
      sum += A[i];
    }
    printf("%lu\n", sum);
  }
  free(A);
  free(B);
  free(C);
  return 0;
}
