#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mapper;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    sum += temp;
    mapper[temp]++;
  }
  int test;
  cin >> test;
  while (test--) {
    int x, y;
    cin >> x >> y;
    int xCount = mapper[x];
    mapper[x] = 0;
    mapper[y] += xCount;
    sum -= xCount * x;
    sum += xCount * y;
    cout << sum << endl;
  }
  return 0;
}
