#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[100000], q, b, c;
  long long int sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    sum = 0;
    cin >> b >> c;
    for (int i = 0; i < n; i++) {
      if (a[i] == b) {
        a[i] = c;
        sum += a[i];
      } else
        sum += a[i];
    }
    cout << sum << "\n";
  }
}
