#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m[10001];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m[i];
  }
  int a, p, q;
  cin >> a;
  for (int i = 0; i < a; i++) {
    unsigned long long a, b, s = 0;
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
      int p = a;
      int q = b;
      if (p == m[i]) {
        swap(q, m[i]);
      }
      s = s + m[i];
    }
    cout << s << "\n";
  }
  return 0;
}
