#include <bits/stdc++.h>
using namespace std;
class Hoge {
 public:
  long int i0;
  long int isum0;
  int i1, N0, Q;
  string s0;
  int* iarray0;
  int* iarrayb;
  int* iarrayc;
  int* iarrayn;
  Hoge(int);
  void func0();
  ~Hoge();
  void array0();
  void array1();
  void printarray0();
  void count0();
  void printarrayn();
  void convert0();
};
Hoge::Hoge(int itemp) {
  i0 = itemp;
  isum0 = 0;
}
void Hoge::func0() { i0 += 1; }
void Hoge::array0() {
  cin >> N0;
  iarray0 = new int[N0];
  for (int i0 = 0; i0 < N0; i0++) {
    cin >> iarray0[i0];
  }
}
void Hoge::array1() {
  cin >> Q;
  iarrayb = new int[Q];
  iarrayc = new int[Q];
  for (int i0 = 0; i0 < Q; i0++) {
    cin >> iarrayb[i0];
    cin >> iarrayc[i0];
  }
}
void Hoge::count0() {
  iarrayn = new int[10 ^ 5 + 1];
  for (int i0 = 0; i0 < N0; i0++) {
    iarrayn[iarray0[i0]]++;
  }
  for (int i0 = 0; i0 < (10 ^ 5 + 1); i0++) {
    isum0 += i0 * iarrayn[i0];
  }
}
void Hoge::convert0() {
  int inc0;
  for (int i0 = 0; i0 < Q; i0++) {
    inc0 = (iarrayc[i0] - iarrayb[i0]) * iarrayn[iarrayb[i0]];
    isum0 += inc0;
    cout << isum0 << endl;
    iarrayn[iarrayc[i0]] += iarrayn[iarrayb[i0]];
    iarrayn[iarrayb[i0]] = 0;
  }
}
Hoge::~Hoge() {
  delete[] iarray0;
  delete[] iarrayb;
  delete[] iarrayc;
  delete[] iarrayn;
}
void Hoge::printarray0() {
  for (int i0 = 0; i0 < N0; i0++) {
    cout << "iarray0[" << i0 << "]=" << iarray0[i0] << endl;
  }
  cout << "---------" << endl;
}
void Hoge::printarrayn() {
  for (int i0 = 0; i0 < 20; i0++) {
    cout << "iarrayn[" << i0 << "]=" << iarrayn[i0] << endl;
  }
  cout << "---------" << endl;
}
int main() {
  int N;
  Hoge* hoge = new Hoge(0);
  hoge->array0();
  hoge->array1();
  hoge->count0();
  hoge->convert0();
  return 0;
  delete hoge;
}
