#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using ll = long long;
using namespace std;
const long long MOD = 1000000007;
const ll LINF = 1LL << 50;
int main() {
  int N;
  cin >> N;
  vector<int> nums(100000, 0);
  int ans = 0;
  for (int n = 0; n < (int)(N); n++) {
    int a;
    cin >> a;
    nums[a - 1] += 1;
    ans += a;
  }
  int Q;
  cin >> Q;
  for (int q = 0; q < (int)(Q); q++) {
    int b, c;
    cin >> b >> c;
    int tmp;
    tmp = nums[b - 1];
    nums[b - 1] = 0;
    nums[c - 1] += tmp;
    ans = ans + (c - b) * tmp;
    cout << ans << endl;
  }
}
