#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int aval[n];
  int anum[n];
  int i, j;
  int num;
  int tail = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &num);
    for (j = 0;; j++) {
      if (j == tail) {
        aval[tail] = num;
        anum[tail] = 1;
        tail++;
        break;
      } else if (aval[j] == num) {
        anum[j]++;
        break;
      }
    }
  }
  int q;
  scanf("%d", &q);
  int b[n], c[n];
  for (i = 0; i < q; i++) {
    scanf("%d%d", &b[i], &c[i]);
  }
  for (j = 0; j < q; j++) {
    for (i = 0; i < tail; i++) {
      if (aval[i] == b[j]) {
        aval[i] = c[j];
      }
    }
    int sum;
    for (i = 0, sum = 0; i < tail; i++) {
      sum += aval[i] * anum[i];
    }
    printf("%d\n", sum);
  }
  return 0;
}
