#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n, m, a, b;
  cin >> n;
  int A[n];
  for (i = 0; i < n; i++) cin >> A[i];
  cin >> m;
  for (i = 0; i < m; i++) {
    long long int sum = 0;
    cin >> a >> b;
    for (j = 0; j < n; j++)
      if (A[j] == a) A[j] = b;
    for (j = 0; j < n; j++) sum += A[j];
    cout << sum << endl;
  }
}
