#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, *num, i, line, b, c, j, sum = 0;
  cin >> n;
  num = new int[n];
  for (i = 0; i < n; i++) {
    cin >> num[i];
  }
  cin >> line;
  for (i = 0; i < line; i++) {
    cin >> b >> c;
    sum = 0;
    for (j = 0; j < n; j++) {
      if (num[j] == b) {
        num[j] = c;
      }
      sum = sum + num[j];
    }
    cout << sum << endl;
  }
  delete[] num;
  return 0;
}
