#include <bits/stdc++.h>
using namespace std;
int i, j;
int main() {
  int n;
  scanf("%d", &n);
  int arr[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  int q;
  scanf("%d", &q);
  int old_val, new_val;
  while (q--) {
    long long int sum = 0;
    scanf("%d", &old_val);
    scanf("%d", &new_val);
    replace(arr, arr + n, old_val, new_val);
    for (i = 0; i < n; i++) {
      sum += arr[i];
    }
    printf("%d\n", sum);
  }
}
