#include <bits/stdc++.h>
using namespace std;
int nums[100005];
int main() {
  long long sum = 0;
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int temp;
    cin >> temp;
    nums[temp]++;
    sum += temp;
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int b, c;
    cin >> b >> c;
    int temp = nums[b];
    nums[b] = 0;
    nums[c] += temp;
    sum -= temp * b;
    sum += temp * c;
    cout << sum << "\n";
  }
}
