#include <bits/stdc++.h>
using namespace std;
constexpr auto INFI = 2147483647;
const long long INFL = 9223372036854775807;
int main() {
  const int MAX = 100005;
  int n, q;
  cin >> n;
  vector<int> numcount(MAX, 0);
  long long ans = 0;
  for (int i = 0; i < (n); i++) {
    int tmp;
    cin >> tmp;
    numcount[tmp]++;
    ans += tmp;
  }
  cin >> q;
  for (int i = 0; i < (q); i++) {
    int tmp_b, tmp_c;
    cin >> tmp_b >> tmp_c;
    ans -= tmp_b * numcount[tmp_b];
    ans += tmp_c * numcount[tmp_b];
    numcount[tmp_c] += numcount[tmp_b];
    numcount[tmp_b] = 0;
    cout << ans << endl;
  }
  return 0;
}
