#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  T f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  x *= f;
}
inline void d_read(double &x) {
  x = 0.0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  if (c == '.') {
    double num = 1.0;
    c = getchar();
    for (; isdigit(c); c = getchar()) x = x + (num /= 10) * (c ^ 48);
  }
  x *= f;
}
template <typename T>
inline void w(T x) {
  if (x > 9) w(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x, char c) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  w(x);
  putchar(c);
}
int a[100005];
int main() {
  int n;
  read(n);
  long long s = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    read(x);
    a[x]++;
    s += x;
  }
  int m;
  read(m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    read(x);
    read(y);
    s -= a[x] * x;
    s += a[x] * y;
    a[y] += a[x];
    a[x] = 0;
    write(s, '\n');
  }
  return 0;
}
