#include <bits/stdc++.h>
using namespace std;
int n;
int a[100000];
int q;
int b[100000];
int c[100000];
void solve() {
  sort(a, a + n);
  int sum = accumulate(a, a + n, 0);
  for (int i = 0; i < q; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i]) {
        cnt++;
        a[j] = c[i];
      }
    }
    sum += (c[i] - b[i]) * cnt;
    printf("%d\n", sum);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &b[i]);
    scanf("%d", &c[i]);
  }
  solve();
}
