#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  scanf("%d", &n);
  int arr[n];
  vector<int> v[100001];
  int sum = 0;
  for (i = 0; i < n; ++i) {
    scanf("%d", &arr[i]);
    v[arr[i]].push_back(i);
    sum += arr[i];
  }
  int q;
  int a, b;
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &a, &b);
    int p = v[a].size();
    for (i = 0; i < p; ++i) {
      arr[v[a][i]] = b;
      sum += b - a;
      v[b].push_back(v[a][i]);
    }
    v[a].clear();
    printf("%d\n", sum);
  }
}
