#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N, Q;
  cin >> N;
  int a;
  vector<int> nums;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a;
    nums.push_back(a);
    sum += a;
  }
  cin >> Q;
  int b, c;
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    for (int j = 0; j < N; j++) {
      if (nums[j] == b) {
        nums[j] = c;
        if (b > c) {
          sum -= (b - c);
        } else {
          sum += (c - b);
        }
      }
    }
    cout << sum << "\n";
  }
}
