#include <bits/stdc++.h>
using namespace std;
long long power(long long base, long long e) {
  long long answer = 1;
  while (e) {
    if (e % 2 == 1) {
      answer *= base;
    }
    base *= base;
    e /= 2;
  }
  return answer;
}
void mergearr(long long arr[], long long l, long long m, long long r) {
  long long i, j, k;
  long long n1 = m - l + 1;
  long long n2 = r - m;
  long long L[n1], R[n2];
  for (i = 0; i < n1; i++) L[i] = arr[l + i];
  for (i = 0; i < n2; i++) R[i] = arr[m + 1 + i];
  i = 0;
  j = 0;
  k = l;
  while (i < n1 && j < n2) {
    if (L[i] <= R[j]) {
      arr[k] = L[i];
      i++;
    } else {
      arr[k] = R[j];
      j++;
    }
    k++;
  }
  while (i < n1) {
    arr[k] = L[i];
    i++;
    k++;
  }
  while (j < n2) {
    arr[k] = R[j];
    j++;
    k++;
  }
}
void mergesort(long long arr[], long long l, long long r) {
  if (l < r) {
    long long m = l + (r - l) / 2;
    mergesort(arr, l, m);
    mergesort(arr, m + 1, r);
    mergearr(arr, l, m, r);
  }
}
void sieveprimes(long long n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long i = 2; i * i <= n; i++) {
    if (prime[i] == true) {
      for (long long j = i * i; j <= n; j += i) {
        prime[j] = false;
      }
    }
  }
  for (int p = 2; p <= n; p++)
    if (prime[p]) cout << p << " ";
}
int main() {
  long long n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long q;
  cin >> q;
  long long fin, rep;
  for (int i = 0; i < q; i++) {
    cin >> fin >> rep;
    for (int i = 0; i < n; i++) {
      if (a[i] == fin) {
        sum -= a[i];
        a[i] = rep;
        sum += a[i];
      }
    }
    cout << sum << endl;
  }
}
