#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vec a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  int q;
  cin >> q;
  vec ans(q, 0);
  int sum = 0;
  for (int i = 0; i < (int)(n); i++) sum += a[i];
  for (int i = 0; i < (int)(q); i++) {
    int cnt = 0;
    int b, c;
    cin >> b >> c;
    for (int j = 0; j < (int)(n); j++) {
      if (a[j] == b) {
        a[j] = c;
        cnt++;
      }
    }
    sum += (c - b) * cnt;
    ans[i] = sum;
  }
  for (int x : ans) cout << x << endl;
}
