#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
const ll INF = 1LL << 60;
ll mod = 1000000007;
vector<int> num(100005, 0);
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    num[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int b, c, tmp;
    cin >> b >> c;
    sum = sum - num[b] * b + num[b] * c;
    num[c] += num[b];
    num[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
