#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
vector<bool> seen;
void dfs(const Graph &G, int v) {
  seen[v] = true;
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue;
    dfs(G, next_v);
  }
}
bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  long long N, Q, tmp;
  cin >> N;
  long long naka[100010] = {};
  set<long long> A;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    if (naka[tmp] == 0) A.insert(tmp);
    naka[tmp]++;
  }
  cin >> Q;
  long long B[100010];
  long long C[100010];
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  long long sum;
  for (int i = 0; i < Q; i++) {
    sum = 0;
    naka[C[i]] += naka[B[i]];
    naka[B[i]] = 0;
    A.erase(B[i]);
    A.insert(C[i]);
    for (auto x : A) {
      sum += x * naka[x];
    }
    cout << sum << endl;
  }
}
