#include <iostream>
#include <vector>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <utility>
#include <boost/foreach.hpp>
#include <cmath>

std::vector<long long int> ans;
long long int N, Q, sum;
long long int A[10000 + 1], B[10000 + 1], C[10000 + 1];
long long int count[100000 + 1];

void func() {
  for (int i = 1; i <= N; i++) {
    sum += A[i];
    count[A[i]]++;
  }
}

int main() {
  std::cin >> N;
  for (int i = 1; i <= N; i++) {
    std::cin >> A[i];
  }
  std::cin >> Q;
  for (int i = 1; i <= Q; i++) {
    std::cin >> B[i] >> C[i];
  }

  func();

  for (int i = 1; i <= Q; i++) {
    long long int tmp = count[B[i]];
    count[B[i]] = 0;
    count[C[i]] += tmp;
    sum = sum + tmp * (C[i] - B[i]);
    ans.push_back(sum);
  }

  for (int i = 0; i < ans.size(); i++) {
    std::cout << ans[i] << std::endl;
  }

  return 0;
}