// ~~ icebear love attttttt ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
template<class T>
bool minimize(T &a, const T &b) {
if (a > b) return a = b, true;
return false;
}
template<class T>
bool maximize(T &a, const T &b) {
if (a < b) return a = b, true;
return false;
}
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebearat"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 2e5 + 5;
int n, m, H;
int l[N], s[N];
vector<int> G[N];
ll dist[N];
void init(void) {
cin >> n >> m >> H;
FOR(i, 1, n) cin >> l[i];
FOR(i, 1, n) cin >> s[i];
FOR(i, 1, m) {
int u, v;
cin >> u >> v;
G[u].pb(v);
G[v].pb(u);
}
}
ll extended_euclid(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll x1, y1;
ll d = extended_euclid(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
ll find_weight(int l_u, int s_u, int l_v, int s_v, ll lower) {
// l_u + k * s_u = l_v + k * s_v (mod H) and k > lower
ll a = s_v - s_u, b = H, c = l_u - l_v;
ll x, y;
ll g = extended_euclid(abs(a), abs(b), x, y);
if (c % g) return INF;
ll x0 = (c / g) * x, y0 = (c / g) * y;
if (a < 0) x0 = -x0;
if (b < 0) y0 = -y0;
// k = x + T * b / g > lower -> T > (lower - x) * g / b
ll T = (ll)ceil(1.0 * (lower - x0) * g / b);
return x0 + T * b / g;
}
void process(void) {
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
FOR(i, 0, n) dist[i] = INF;
dist[1] = -1;
pq.push(mp(-1, 1));
while(!pq.empty()) {
ll du; int u;
tie(du, u) = pq.top(); pq.pop();
if (du != dist[u]) continue;
for(int v : G[u]) {
ll w = find_weight(l[u], s[u], l[v], s[v], dist[u]);
if (minimize(dist[v], w)) pq.push(mp(w, v));
}
}
cout << (dist[n] >= dist[0] ? -1 : dist[n] + 1);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) {
init();
process();
}
return 0;
}
Ly8gfn4gaWNlYmVhciBsb3ZlIGF0dHR0dHR0IH5+CiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgcGFpcjxpbnQsIGludD4gaWk7CnR5cGVkZWYgcGFpcjxpbnQsIGlpPiBpaWk7Cgp0ZW1wbGF0ZTxjbGFzcyBUPgogICAgYm9vbCBtaW5pbWl6ZShUICZhLCBjb25zdCBUICZiKSB7CiAgICAgICAgaWYgKGEgPiBiKSByZXR1cm4gYSA9IGIsIHRydWU7CiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQoKdGVtcGxhdGU8Y2xhc3MgVD4KICAgIGJvb2wgbWF4aW1pemUoVCAmYSwgY29uc3QgVCAmYikgewogICAgICAgIGlmIChhIDwgYikgcmV0dXJuIGEgPSBiLCB0cnVlOwogICAgICAgIHJldHVybiBmYWxzZTsKICAgIH0KCiNkZWZpbmUgRk9SKGksYSxiKSBmb3IoaW50IGk9KGEpOyBpPD0oYik7ICsraSkKI2RlZmluZSBGT1JSKGksYSxiKSBmb3IoaW50IGk9KGEpOyBpPj0oYik7IC0taSkKI2RlZmluZSBSRVAoaSwgbikgZm9yKGludCBpPTA7IGk8KG4pOyArK2kpCiNkZWZpbmUgUkVEKGksIG4pIGZv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