#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
long long ksm(int a, int b) {
  if (b == 1)
    return a;
  else {
    int s = ksm(a, b / 2);
    if (b % 2 == 0)
      return (s % inf) * (s % inf);
    else
      return (s % inf) * (s % inf) * a % inf;
  }
}
int gcd(int a, int b) {
  int x = a % b;
  while (x > 0) {
    a = b;
    b = x;
    x = a % b;
  }
  return b;
}
const int MAXN = 1000010;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
class Bignum {
 public:
  int w;
  long long num[100];
  Bignum operator=(long long x) {
    memset(num, 0, sizeof num);
    w = 0;
    while (x) {
      num[++w] = x % 10;
      x /= 10;
    }
    if (w == 0) w = 1;
    return *this;
  }
  Bignum operator*(long long x) {
    for (int i = 1; i <= w; i++) {
      num[i] *= x;
    }
    for (int i = 1; i <= w; i++) {
      if (num[i] > 9) {
        num[i + 1] += num[i] / 10;
        num[i] %= 10;
        if (i == w) w++;
      }
    }
    return *this;
  }
  Bignum operator+(long long x) {
    num[1] += x;
    for (int i = 1; i <= w; i++) {
      if (num[i] > 9) {
        num[i + 1] += num[i] / 10;
        num[i] %= 10;
        if (i == w) w++;
      }
    }
    return *this;
  }
  void print() {
    for (int i = w; i; i--) printf("%lld", num[i]);
    puts("");
  }
};
int n, m, T;
int a[110000];
int main() {
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    ++a[x];
    sum += x;
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    int b, c;
    scanf("%d%d", &b, &c);
    int s = a[b];
    a[b] = 0;
    a[c] += s;
    sum -= b * s;
    sum += c * s;
    cout << sum << endl;
  }
  return 0;
}
