#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int array[n];
  for (int x = 0; x < n; x++) cin >> array[x];
  int t;
  cin >> t;
  int p, q;
  for (int x = 0; x < t; x++) {
    cin >> p >> q;
    for (int y = 0; y < n; y++) {
      if (array[y] == p) array[y] = q;
    }
    int sum = 0;
    for (int i = 0; i < n; i++) sum += array[i];
    cout << sum << "\n";
  }
}
