#include <bits/stdc++.h>
int main() {
  int size, size2;
  scanf("%d", &size);
  int arr[size];
  for (int i = 0; i < size; i++) {
    scanf("%d", &arr[i]);
  }
  scanf("%d", &size2);
  int cal[size2][2];
  for (int i = 0; i < size2; i++) {
    for (int j = 0; j < 2; j++) {
      scanf("%d", &cal[i][j]);
    }
  }
  int sum = 0;
  for (int i = 0; i < size2; i++) {
    for (int j = 0; j < size; j++) {
      if (arr[j] == cal[i][0]) {
        arr[j] = cal[i][1];
      }
      sum += arr[j];
    }
    printf("%d\n", sum);
    sum = 0;
  }
}
