#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

const int N=2e5+5;

ll a[N],b[N],k[N],t[N],d[N],n,m,x,y;

vector<pll> v[N];

int main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
rep(i,0,N-1)d[i]=1e18+7;
cin>>n>>m>>x>>y;

rep(i,0,m-1)
{
	cin>>a[i]>>b[i]>>t[i]>>k[i];
	v[a[i]].pb({b[i],i});
	v[b[i]].pb({a[i],i});
}

priority_queue<pll> q;
d[x]=0;
q.push({0,x});

while(!q.empty())
{
	ll dis=-q.top().ff,at=q.top().ss;
	q.pop();
	if(dis>d[at])continue;
	tr(v[at],it)
	{
		ll to=it->ff,id=it->ss;
		ll dis2=dis+(k[id]-dis%k[id])%k[id]+t[id];
		if(dis2<d[to])
		{
			d[to]=dis2;
			q.push({-dis2,to});
		}
	}
}
if(d[y]<1e17)
{
	ol(d[y]);
}
else
{
	ol("-1");
}
return 0;
}




#include <bits/stdc++.h>
#define fi first
#define se second
#define lc (x << 1)
#define rc (x << 1 | 1)
#define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define IT iterator
#define vi vector<int>
#define TP template <class o>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = 110, S = N * N * N / 2, size = 1 << 20, inf = 2e9;

// char buf[size],*p1=buf,*p2=buf;
template <class o> void qr(o& x) {
    char c = gc;
    x = 0;
    int f = 1;
    while (!isdigit(c)) {
        if (c == '-')
            f = -1;
        c = gc;
    }
    while (isdigit(c))
        x = x * 10 + c - '0', c = gc;
    x *= f;
}
template <class o> void qw(o x) {
    if (x / 10)
        qw(x / 10);
    putchar(x % 10 + '0');
}
template <class o> void pr1(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar(' ');
}
template <class o> void pr2(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar('\n');
}

int n, k, p, f[N][S], sum[N], s[N], ou[N];

void ad(ll& x, ll y) {
    x += y;
    if (x >= p)
        x -= p;
}

int main() {
    qr(n);
    qr(k);
    qr(p);
    f[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        sum[i] += sum[i - 1] + i * k;
        for (int j = 0; j < i; j++)
            s[j] = 0;
        for (int j = 0; j <= sum[i]; j++) {
            int x = j % i;
            s[x] = (s[x] + f[i - 1][j]) % p;
            if (j - (k + 1) * i >= 0)
                s[x] = (s[x] - f[i - 1][j - (k + 1) * i] + p) % p;
            f[i][j] = s[x];
        }
    }
    for (int i = 1, j = n; i <= j; i++, j--) {
        ll ans = 0;
        for (int j = 0; j <= sum[i - 1]; j++)
            ad(ans, (ll)f[i - 1][j] * f[n - i][j] % p);
        ou[i] = ou[j] = ((ans * (k + 1) + p) - 1) % p;
    }
    for (int i = 1; i <= n; i++)
        pr2(ou[i]);
    return 0;
}
