#include <bits/stdc++.h>
const int INF = 1001001001;
const double PI = 3.14159;
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> va;
  map<int, int> num;
  int a;
  for (int i = 0; i < (n); ++i) {
    cin >> a;
    if (num[a] != 0)
      num[a]++;
    else {
      va.push_back(a);
      num[a] = 1;
    }
  }
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < (q); ++i) {
    cin >> b >> c;
    num[c] += num[b];
    num[b] = 0;
    long long sum = 0;
    for (int j = 0; j < (va.size()); ++j) {
      sum += va[j] * num[va[j]];
    }
    cout << sum << endl;
    ;
  }
}
