#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  int sum = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    int cnt = 0;
    cin >> b >> c;
    cnt = count(a.begin(), a.end(), b);
    int diff = c - b;
    replace(a.begin(), a.end(), b, c);
    sum += diff * cnt;
    cout << sum << endl;
  }
  return 0;
}
