#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
const ll INF = 9223372036854775807;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (ll i = 0; i < n; i++) cin >> vec[i];
  ll Ans = 0;
  for (ll i = 0; i < n; i++) Ans += vec[i];
  int Q;
  cin >> Q;
  for (ll i = 0; i < Q; i++) {
    int a = 0;
    int b = 0;
    cin >> a >> b;
    int c = 0;
    for (ll i = 0; i < n; i++) {
      if (vec[i] == a) {
        c++;
        vec[i] = b;
      }
    }
    Ans += (b - a) * c;
    cout << Ans << endl;
  }
}
