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