#include <bits/stdc++.h>
using namespace std;
int binarySearch(int arr[], int l, int r, int x, int y) {
  while (l <= r) {
    int m = l + (r - l) / 2;
    if (arr[m] == x) arr[m] = y;
    if (arr[m] < x)
      l = m + 1;
    else
      r = m - 1;
  }
  return -1;
}
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int r = binarySearch(a, 0, n - 1, b, c);
    int sum = 0;
    sum = accumulate(a, a + n, sum);
    cout << sum << endl;
  }
  return 0;
}
