#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, i, j, cnt = 0, b, a, x, sum = 0, temp = 0;
  cin >> n;
  long long int ar[n];
  for (i = 0; i < n; i++) cin >> ar[i];
  cin >> b;
  while (b--) {
    sum = 0;
    cin >> a >> x;
    temp = x;
    for (i = 0; i < n; i++) {
      x = temp;
      if (ar[i] == a) {
        swap(ar[i], x);
      }
      sum += ar[i];
    }
    cout << sum << endl;
  }
  return 0;
}
