#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
int main() {
  long long int a, b, x, n, m, k, sum = 0, ans = 0, res = 0, q;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  cin >> q;
  vector<vector<int>> arrq(q, vector<int>(2));
  for (int i = 0; i < q; ++i) {
    cin >> a >> b;
    for (int i = 0; i < n; ++i) {
      if (arr[i] == a) {
        arr[i] = b;
        sum -= a;
        sum += b;
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
