#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, k;
  vector<int> v;
  cin >> n;
  v.resize(n + 1, 0);
  int preSum = 0;
  for (int i = 1, x; i <= n; i++) {
    cin >> x;
    v[i] = x;
    preSum += x;
  }
  cin >> k;
  int cnt;
  for (int i = 1, x, y; i <= k; i++) {
    cnt = 0;
    cin >> x >> y;
    for (int j = 1; j <= n; j++) {
      if (v[j] == x) {
        v[j] = y;
        cnt++;
      }
    }
    if (x > y)
      preSum -= abs(x - y) * cnt;
    else
      preSum += abs(x - y) * cnt;
    cout << preSum << endl;
  }
}
