#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, Y, X, K, iK, a[N], ba[N], iba[N];
vector<int> e[N];
long long ans = 0;
int mx[N], sz[N], Size, rt;
bool vis[N];
int In[2][N], Out[2][N];
map<int, int> Up, Dn;
inline int add(const int &x, const int &y) {
  return x + y < Y ? x + y : x + y - Y;
}
inline int sub(const int &x, const int &y) {
  return x - y < 0 ? x - y + Y : x - y;
}
inline int mul(const int &x, const int &y) {
  return (int)((long long)x * y % Y);
}
int ksm(int x, int y = Y - 2) {
  int ss = 1;
  for (; y; y >>= 1, x = mul(x, x))
    if (y & 1) ss = mul(ss, x);
  return ss;
}
inline int Max(const int &x, const int &y) { return x > y ? x : y; }
inline int Min(const int &x, const int &y) { return x < y ? x : y; }
void getrt(int u, int ff) {
  sz[u] = 1, mx[u] = 0;
  for (auto v : e[u])
    if (v != ff && !vis[v])
      getrt(v, u), sz[u] += sz[v], mx[u] = Max(mx[u], sz[v]);
  mx[u] = Max(mx[u], Size - sz[u]);
  if (mx[rt] > mx[u]) rt = u;
}
void init(int u, int ff, int anc, int up, int dn, int dep) {
  up = add(mul(up, K), a[u]), dn = add(dn, mul(a[u], ba[dep - 1]));
  if (up == X) ++In[1][anc];
  if (dn == X) ++Out[1][anc];
  sz[u] = 1;
  for (auto v : e[u])
    if (v != ff && !vis[v]) init(v, u, anc, up, dn, dep + 1), sz[u] += sz[v];
}
void getans(int u, int ff, int up, int dn, int dep) {
  up = add(mul(up, K), a[u]), dn = add(dn, mul(a[u], ba[dep - 1]));
  Out[1][u] += Dn[mul(sub(X, up), iba[dep])];
  In[1][u] += Up[dn];
  for (auto v : e[u])
    if (v != ff && !vis[v]) getans(v, u, up, dn, dep + 1);
}
void update(int u, int ff, int up, int dn, int dep) {
  up = add(mul(up, K), a[u]), dn = add(dn, mul(a[u], ba[dep - 1]));
  ++Up[mul(sub(X, up), iba[dep])];
  ++Dn[dn];
  for (auto v : e[u])
    if (v != ff && !vis[v]) update(v, u, up, dn, dep + 1);
}
void solve(int u) {
  vis[u] = 1, init(u, 0, u, 0, 0, 1);
  Up[mul(sub(X, a[u]), iba[1])] = 1, Dn[a[u]] = 1;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i];
    if (vis[v]) continue;
    getans(v, u, 0, 0, 1), update(v, u, a[u], a[u], 2);
  }
  Up.clear(), Dn.clear();
  for (int i = e[u].size() - 1; ~i; i--) {
    int v = e[u][i];
    if (vis[v]) continue;
    getans(v, u, 0, 0, 1), update(v, u, a[u], a[u], 2);
  }
  Up.clear(), Dn.clear();
  for (auto v : e[u])
    if (!vis[v]) mx[rt = 0] = Size = sz[v], getrt(v, 0), solve(rt);
}
int main() {
  scanf("%d%d%d%d", &n, &Y, &K, &X), iK = ksm(K);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  ba[0] = iba[0] = 1;
  for (int i = 1; i <= n; i++)
    ba[i] = mul(ba[i - 1], K), iba[i] = mul(iba[i - 1], iK);
  for (int i = 1, x, y; i < n; i++)
    scanf("%d%d", &x, &y), e[x].push_back(y), e[y].push_back(x);
  mx[rt = 0] = Size = n, getrt(1, 0), solve(rt);
  for (int i = 1; i <= n; i++) {
    In[0][i] = n - In[1][i], Out[0][i] = n - Out[1][i];
    ans += 2ll * In[0][i] * In[1][i] + 2ll * Out[0][i] * Out[1][i];
    ans += 1ll * In[0][i] * Out[1][i] + 1ll * In[1][i] * Out[0][i];
  }
  printf("%I64d\n", (long long)n * n * n - ans / 2);
  return 0;
}
