#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, n, x, y;
  map<int, int> ma;
  long long int sum = 0;
  scanf("%d", &a);
  int arr[a + 2];
  for (int i = 1; i <= a; i++) {
    scanf("%d", &arr[i]);
    sum += arr[i];
    ma[arr[i]]++;
  }
  scanf("%d", &n);
  long long int ar[n + 2];
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &x, &y);
    ma[y] = ma[x] + ma[y];
    sum = sum - (long long int)(ma[x] * x) + (long long int)(ma[x] * y);
    ma[x] = 0;
    ar[i] = sum;
  }
  for (int i = 1; i <= n; i++) printf("%d\n", ar[i]);
  return 0;
}
