#include <bits/stdc++.h>
using namespace std;
const int MN = 555;
struct MCF {
  int V, E, tf, tc;
  vector<int> la, nxt, oppo, capa, cost;
  void init(int V_) {
    V = V_;
    E = tf = tc = 0;
    la.clear();
    nxt.clear();
    oppo.clear();
    cost.clear();
    la = vector<int>(V, -1);
  }
  void add(int u, int v, int ca, int co) {
    nxt.push_back(la[u]);
    la[u] = E++;
    oppo.push_back(v);
    capa.push_back(ca);
    cost.push_back(co);
  }
  bool spfa(int src, int snk) {
    vector<int> dist(V, 1e9), inq(V, 0), fe(V, -1);
    queue<int> q;
    q.push(src);
    inq[src] = 1;
    dist[src] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      inq[u] = 0;
      for (int i = la[u]; i != -1; i = nxt[i]) {
        int v = oppo[i];
        if (capa[i] && dist[v] > dist[u] + cost[i]) {
          dist[v] = dist[u] + cost[i];
          fe[v] = i;
          if (!inq[v]) {
            q.push(v);
            inq[v] = 1;
          }
        }
      }
    }
    if (dist[snk] == 1e9) return false;
    tf++;
    tc += dist[snk];
    int u = snk;
    while (u != src) {
      int e = fe[u];
      capa[e]--;
      capa[e ^ 1]++;
      u = oppo[e ^ 1];
    }
    return true;
  }
} mcf;
int N, root1, root2, Q1, Q2, tot1, tot2, V, src, snk;
int A[MN], cnt1[MN], cnt2[MN], dp1[MN], dp2[MN];
vector<int> adj1[MN], adj2[MN];
void dfs1(int u, int p) {
  for (int i = 0; i < adj1[u].size(); i++) {
    int v = adj1[u][i];
    if (v == p) continue;
    dfs1(v, u);
    dp1[u] += dp1[v];
    if (!cnt1[v]) {
      mcf.add(u, v, 1e9, 0);
      mcf.add(v, u, 0, 0);
    }
  }
  if (cnt1[u]) {
    if (dp1[u] > cnt1[u]) {
      printf("-1");
      exit(0);
    }
    mcf.add(src, u, cnt1[u] - dp1[u], 0);
    mcf.add(u, src, 0, 0);
    dp1[u] = cnt1[u];
  }
}
void dfs2(int u, int p) {
  for (int i = 0; i < adj2[u].size(); i++) {
    int v = adj2[u][i];
    if (v == p) continue;
    dfs2(v, u);
    dp2[u] += dp2[v];
    if (!cnt2[v]) {
      mcf.add(N + v, N + u, 1e9, 0);
      mcf.add(N + u, N + v, 0, 0);
    }
  }
  if (cnt2[u]) {
    if (dp2[u] > cnt2[u]) {
      printf("-1");
      exit(0);
    }
    mcf.add(N + u, snk, cnt2[u] - dp2[u], 0);
    mcf.add(snk, N + u, 0, 0);
    dp2[u] = cnt2[u];
  }
}
int main() {
  scanf("%d %d %d", &N, &root1, &root2);
  root1--;
  root2--;
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    adj1[u].push_back(v);
    adj1[v].push_back(u);
  }
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    adj2[u].push_back(v);
    adj2[v].push_back(u);
  }
  scanf("%d", &Q1);
  for (int i = 0; i < Q1; i++) {
    int k, x;
    scanf("%d %d", &k, &x);
    k--;
    cnt1[k] = x;
  }
  scanf("%d", &Q2);
  for (int i = 0; i < Q2; i++) {
    int k, x;
    scanf("%d %d", &k, &x);
    k--;
    cnt2[k] = x;
  }
  if (cnt1[root1] != cnt2[root2]) {
    printf("-1");
    return 0;
  }
  V = 2 * N + 2, src = V - 2, snk = V - 1;
  mcf.init(V);
  dfs1(root1, -1);
  dfs2(root2, -1);
  for (int i = 0; i < N; i++) {
    mcf.add(i, N + i, 1, -A[i]);
    mcf.add(N + i, i, 0, A[i]);
  }
  while (mcf.spfa(src, snk))
    ;
  if (mcf.tf != cnt1[root1])
    printf("-1");
  else
    printf("%d", -mcf.tc);
}
