#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int array[N];
  int i;
  for (i = 0; i < N; i++) {
    cin >> array[i];
  }
  int Q;
  cin >> Q;
  double s[Q];
  for (i = 0; i < Q; i++) {
    int B;
    int C;
    cin >> B >> C;
    for (int i = 0; i < N; i++) {
      if (array[i] == B) {
        array[i] = C;
      }
    }
    double Sum = 0;
    for (int i = 0; i < N; i++) {
      Sum = Sum + array[i];
    }
    s[i] = Sum;
  }
  for (int i = 0; i < Q; i++) {
    cout << s[i] << endl;
  }
}
