#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, sum = 0;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += a;
    v.push_back(a);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    sum = sum + count(v.begin(), v.end(), x) * (y - x);
    cout << sum << endl;
    for (int j = 0; j < n; j++) {
      if (v[j] == x) {
        v[j] = y;
      }
    }
  }
}
