#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool isPrime(int a) {
  if (a == 1) return false;
  if (a == 2) return true;
  if (a % 2 == 0) return false;
  for (int i = 3; i < sqrt(a) + 1; i += 2)
    if (a != i and a % i == 0) return false;
  return true;
}
void execute() {
  int n;
  cin >> n;
  long long sum = 0;
  vector<int> a(n);
  map<int, int> dl;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    dl[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (long long i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  cerr << sum << endl;
  for (long long i = 0; i < q; i++) {
    sum += ((c[i] - b[i]) * dl[b[i]]);
    dl[c[i]] += dl[b[i]];
    cout << sum << endl;
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  execute();
  return 0;
}
