#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  int arr[100000] = {};
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int t = 0;
  for (int i = 0; i < n; i++) {
    t += arr[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] == b) {
        cnt++;
        arr[i] = c;
      }
    }
    t += cnt * (c - b);
    cout << t << '\n';
  }
  return 0;
}
