#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m[10001];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m[i];
  }
  long long int a, p, q;
  cin >> a;
  for (long long int i = 0; i < a; i++) {
    int d, b, s = 0;
    cin >> d >> b;
    for (long long int i = 0; i < n; i++) {
      long long int p = d;
      long long int q = b;
      if (p == m[i]) {
        swap(q, m[i]);
      }
      s = s + m[i];
    }
    cout << s << endl;
  }
}
