#include <bits/stdc++.h>
using namespace std;
int main() {
  int n1, n2, a[100];
  cin >> n1;
  for (int i = 0; i < n1; ++i) {
    cin >> a[i];
  }
  cin >> n2;
  for (int i = 0; i < n2; ++i) {
    int x, y, tong = 0;
    cin >> x >> y;
    for (int j = 0; j < n1; ++j) {
      if (a[i] == x) a[i] = y;
      tong += a[i];
    }
    cout << tong << endl;
  }
}
