#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long c;
  if (a < b) {
    c = a;
    a = b;
    b = c;
  }
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
long long lcm(long long a, long long b) {
  long long c;
  c = a * b / gcd(a, b);
  return c;
}
int sort_greater(int m, int n) {
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  for (int i = 0; i < n; i++) {
    cout << a[i];
  }
  return 0;
}
int bubblesort(int a[], int n) {
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = n - 1; j >= i + 1; j--) {
      if (a[j] < a[j - 1]) {
        swap(a[j], a[j - 1]);
        flag = 1;
        sw += 1;
      }
    }
  }
  return sw;
}
int a_z() {
  for (int i = 0; i <= ('Z' - 'A'); i++) {
    cout << (char)('A' + i);
  }
  return 0;
}
int selecttionsort(int a[], int n) {
  int t, sw = 0, minj;
  for (int i = 0; i < n - 1; i++) {
    minj = i;
    for (int j = 0; j < n - 1; j++) {
      if (a[j] < a[minj]) {
        minj = j;
      }
    }
    t = a[i];
    a[i] = a[minj];
    a[minj] = t;
    if (i != minj) sw += 1;
  }
  return sw;
}
bool is_prime(int x) {
  if (x <= 1) return false;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}
const long long mod = 1000000007;
map<string, int> memo;
using P = pair<long long, long long>;
long long findIndex(int value, vector<long long> a) {
  for (long long i = 0; i < (long long)a.size(); i++) {
    if (a[i] == value) {
      return i;
    }
  }
  return -1;
}
long long nCr(long long n, long long r) {
  long long a = 1;
  for (long long i = n; i > n - r; --i) {
    a = a * i;
  }
  for (long long i = 1; i < r + 1; ++i) {
    a = a / i;
  }
  return a;
}
const int INF = 1001001001;
int main() {
  int n, q;
  cin >> n;
  map<long long, long long> a;
  for (long long i = 0; i < (long long)(n); i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  cin >> q;
  vector<int> b(q), c(q);
  for (long long i = 0; i < (long long)(q); i++) {
    cin >> b[i] >> c[i];
  }
  for (long long i = 0; i < (long long)(q); i++) {
    long long ans = 0;
    a[c[i]] += a[b[i]];
    a[b[i]] = 0;
    for (auto p : a) {
      ans += p.first * p.second;
    }
    cout << ans << endl;
  }
  return 0;
}
