#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, a[100005], q, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  cin >> q;
  while (q--) {
    long long int b, c;
    cin >> b >> c;
    sum = sum - a[b - 1] + a[c - 1];
    a[b - 1] = a[c - 1];
    cout << sum << "\n";
  }
  return 0;
}
