#include <bits/stdc++.h>
using namespace std;
int a, b, c;
int x[100100], y[100100], z[100100];
int main() {
  cin >> a;
  for (int i = 0; i < a; i++) cin >> x[i];
  cin >> b;
  for (int i = 0; i < b; i++) cin >> y[i] >> z[i];
  for (int i = 0; i < b; i++) {
    int n = 0;
    for (int j = 0; j <= a; j++) {
      if (x[j] == y[i]) x[j] = z[i];
      n += x[j];
    }
    cout << n << endl;
  }
  return 0;
}
