#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, sum = 0;
  int MAX = -1;
  int check[100001] = {
      0,
  };
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    check[a]++;
    sum += a;
    MAX = (MAX < a) ? a : MAX;
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int b, c;
    bool flag = false;
    scanf("%d %d", &b, &c);
    for (int j = 1; j <= MAX; j++) {
      if (j == b) {
        flag = true;
        if (j > c) {
          sum -= (check[j] * j) - (check[j] * c);
        } else
          sum += (check[j] * c) - (check[j] * j);
        check[c] += check[j];
        check[j] = 0;
        MAX = (MAX < c) ? c : MAX;
        printf("%d\n", sum);
        break;
      }
    }
    if (!flag) printf("%d\n", sum);
  }
  return 0;
}
