#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using int64 = long long int;
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chadd(T &a, T b) {
  a = a + b;
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
struct UnionFind {
 private:
  const int n;
  int size_;
  vector<int> uf;

 public:
  UnionFind(int _n) : n(_n), size_(_n), uf(_n, -1) {}
  int find(int x) { return (uf[x] < 0) ? x : uf[x] = find(uf[x]); }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -uf[find(x)]; }
  int size() { return size_; }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    size_--;
    if (-uf[x] < -uf[y]) swap(x, y);
    uf[x] += uf[y];
    uf[y] = x;
    return true;
  }
};
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<int> C(100010);
  for (auto e : A) C[e]++;
  ll ans = 0;
  for (int i = 0; i < 100010; i++) ans += 1LL * i * C[i];
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int b, c;
    scanf("%d%d", &b, &c);
    ans -= b * C[b];
    ans += c * C[b];
    C[c] += C[b];
    C[b] = 0;
    printf("%lld\n", ans);
  }
  return 0;
}
