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