#include <bits/stdc++.h>
unsigned long long int input(int *, int);
unsigned long long int work(int *, int, unsigned long long int);
int main() {
  unsigned long long int sum = 0;
  int n, q;
  int data[100001] = {0};
  scanf("%d", &n);
  sum = input(data, n);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    sum = work(data, n, sum);
    printf("%llu\n", sum);
  }
  return 0;
}
unsigned long long int input(int *data, int n) {
  unsigned long long int sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &data[i]);
    sum += data[i];
  }
  return sum;
}
unsigned long long int work(int *data, int n, unsigned long long int sum) {
  int a, b;
  unsigned long long int dif = 0;
  unsigned long long int count = 0;
  scanf("%d %d", &a, &b);
  dif = b - a;
  for (int i = 0; i < n; i++) {
    if (data[i] == a) {
      data[i] = b;
      count++;
    }
  }
  sum += count * dif;
  return sum;
}
