#include <bits/stdc++.h>
using namespace std;
class Hoge {
 public:
  long int s0;
  int k, n, a[100000], b[100000], c[100000], icount, iq;
  double danswer;
  const double PI = 3.14159265358979323846;
  Hoge(int);
  void angle();
  void printp();
  void sort0();
  void sum0();
};
Hoge::Hoge(int n0) {
  n = n0;
  s0 = 0;
}
void Hoge::angle() {
  for (icount = 0; icount < n; icount++) {
    cin >> a[icount];
  }
  cin >> iq;
  for (icount = 0; icount < iq; icount++) {
    cin >> b[icount] >> c[icount];
    for (int icount2 = 0; icount2 < n; icount2++) {
      if (a[icount2] == b[icount]) {
        a[icount2] = c[icount];
      }
    }
    sum0();
  }
}
void Hoge::printp() {
  cout << "==========================" << endl;
  for (int i = 0; i < n; i++) {
    cout << "a[" << i << "]=" << a[i] << endl;
  }
  for (int i = 0; i < iq; i++) {
    cout << "b[" << i << "]=" << b[i] << ",";
    cout << "c[" << i << "]=" << c[i] << endl;
  }
  cout << "=========================" << endl;
}
void Hoge::sort0() {
  for (int i2 = 0; i2 < iq; i2++) {
    s0 = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == b[i2]) {
        a[i] = c[i2];
      }
      s0 += a[i];
    }
    cout << s0 << endl;
  }
}
void Hoge::sum0() {
  long int s0 = 0;
  for (int i = 0; i < n; i++) {
    s0 += a[i];
  }
  cout << s0 << endl;
}
int main() {
  int k, n;
  cin >> n;
  Hoge hoge(n);
  hoge.angle();
}
