#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int x;
  cin >> x;
  while (x--) {
    int a, b;
    cin >> a >> b;
    int c = b;
    for (int i = 0; i < n; i++) {
      if (arr[i] == a) {
        swap(arr[i], b);
        b = c;
      }
    }
    long long int sum = 0;
    for (int i = 0; i < n; i++) sum += arr[i];
    cout << sum << endl;
  }
  return 0;
}
