#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007;
const ll INF = 10000000000000;
ll factorial(ll k) {
  ll sum = 1;
  for (int i = 1; i < k + 1; i++) {
    sum *= i;
  }
  return sum;
}
int main() {
  int n;
  cin >> n;
  ll sum = 0;
  vector<int> a(100001, 0);
  for (int i = 0; i < (int)(n); i++) {
    int tmp;
    cin >> tmp;
    sum += tmp;
    a.at(tmp)++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    int tmp2;
    sum -= b * a.at(b);
    sum += c * a.at(b);
    tmp2 = a.at(b);
    a.at(b) = 0;
    a.at(c) += tmp2;
    cout << sum << endl;
  }
}
