#include <bits/stdc++.h>
using namespace std;
void replace(int *ara, int n, int b, int c) {
  int i;
  for (i = 0; i < n; i++) {
    if (ara[i] == b) {
      ara[i] = c;
    }
  }
}
int sum(int *ara, int n) {
  int i, res = 0;
  for (i = 0; i < n; i++) {
    res = res + ara[i];
  }
  return res;
}
int main() {
  int n, *num, i, line, b, c;
  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;
    replace(num, n, b, c);
    cout << sum(num, n) << endl;
  }
  delete[] num;
  return 0;
}
