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