#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
const ll mod=1e9+7;


 
int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
 
    ll n;
    cin>>n;
    vector<ll> a(n), b(n), p(n);
    set<pair<ll,pair<ll,ll>>> s;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    for(ll i=0;i<n;i++)
        cin>>b[i];
    for(ll i=0;i<n;i++){
        cin>>p[i]; p[i]--;
        if(i!=p[i])
            s.insert({b[p[i]],{i,p[i]}});
    }
    vector<pair<ll,ll>> ans;
    while(s.size()>0){
        ll val=s.rbegin()->first;
        ll c=s.rbegin()->second.first;
        ll to=s.rbegin()->second.second;
        //cout<<val<<" "<<c<<" "<<to<<":   ";
        if(val>=a[c])
            break;
        s.erase(--s.end());
        ll bagpos=p[to];
        ll bagwt=b[bagpos];
        //cout<<bagwt<<" "<<to<<" "<<bagpos<<endl;
        if(bagwt>=a[to])
            break;
        ans.pb({c,to});
        assert(s.find({bagwt,{to,bagpos}})!=s.end());
        p[c]=p[to];
        p[to]=to;
        s.erase({bagwt,{to,bagpos}});
        if(c!=bagpos)
            s.insert({bagwt,{c,bagpos}});
    }
    if(s.size()!=0)
        cout<<-1;
    else{
        cout<<ans.size()<<"\n";
        for(ll i=0;i<ans.size();i++)
            cout<<ans[i].first+1<<" "<<ans[i].second+1<<"\n";
    }


    
    
    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define N 2114514
const ll mod = 998244353;
const ll inf = 1000000000000000000;
bool used[N];
void jk(ll s, ll d[], vector<vector<pair<ll, P>>>& v, ll n) {
    priority_queue<P, vector<P>, greater<P>> que;
    for (int i = 1; i <= n; i++) d[i] = inf;
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        ll x;
        x = que.top().second;
        que.pop();
        if (used[x]) continue;
        used[x] = 1;
        for (auto p : v[x]) {
            ll nv, nt, nc;
            nv = p.first;
            nt = p.second.first;
            nc = p.second.second;
            ll cos = (d[x] + nc - 1) / nc * nc + nt;
            if (cos < d[nv]) {
                d[nv] = cos;
                que.push(P(d[nv], nv));
            }
        }
    }
}
ll dis[N];
int main() {
    ll n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<vector<pair<ll, P>>> v(n + 1);
    for (int i = 0; i < m; i++) {
        ll a, b, t, k;
        cin >> a >> b >> t >> k;
        v[a].push_back({b, {t, k}});
        v[b].push_back({a, {t, k}});
    }
    jk(x, dis, v, n);
    cout << (dis[y] == inf ? -1 : dis[y]) << endl;
    return 0;
}
