#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, q, s, nn, id[N << 2], id2[N << 2], vis[N << 2];
long long d[N << 2];
vector<pair<long long, long long> > g[N << 2];
priority_queue<pair<long long, long long> > pq;
void build(int x, int l, int r, int f) {
  if (!f)
    id[x] = ++nn;
  else
    id2[x] = ++nn;
  for (int i = l; i <= r; i++)
    if (!f)
      g[id[x]].push_back(make_pair(i, 0));
    else
      g[i].push_back(make_pair(id2[x], 0));
  if (l == r) return;
  int mid = l + r >> 1;
  build(x << 1, l, mid, f);
  build(x << 1 | 1, mid + 1, r, f);
}
void upd(int x, int l, int r, int tl, int tr, int u, int w, int f) {
  if (tl <= l && r <= tr) {
    if (!f)
      g[u].push_back(make_pair(id[x], w));
    else
      g[id2[x]].push_back(make_pair(u, w));
    return;
  }
  int mid = l + r >> 1;
  if (tl <= mid) upd(x << 1, l, mid, tl, tr, u, w, f);
  if (tr > mid) upd(x << 1 | 1, mid + 1, r, tl, tr, u, w, f);
}
int main() {
  scanf("%d%d%d", &n, &q, &s);
  nn = n;
  build(1, 1, n, 0);
  build(1, 1, n, 1);
  for (int i = 0, t, u, v, w, l, r; i < q; i++) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%d%d", &u, &v, &w);
      g[u].push_back(make_pair(v, w));
    } else if (t == 2) {
      scanf("%d%d%d%d", &u, &l, &r, &w);
      upd(1, 1, n, l, r, u, w, 0);
    } else if (t == 3) {
      scanf("%d%d%d%d", &u, &l, &r, &w);
      upd(1, 1, n, l, r, u, w, 1);
    }
  }
  for (int i = 1; i <= nn; i++) d[i] = 1e18, vis[i] = 0;
  d[s] = 0;
  pq.push(make_pair(0, s));
  while (!pq.empty()) {
    pair<long long, long long> e = pq.top();
    pq.pop();
    int x = e.second;
    if (vis[x]) continue;
    vis[x] = 1;
    for (int i = 0; i < g[x].size(); i++) {
      pair<long long, long long> e = g[x][i];
      if (!vis[e.first] && d[e.first] > d[x] + e.second) {
        d[e.first] = d[x] + e.second;
        pq.push(make_pair(-d[e.first], e.first));
      }
    }
  }
  for (int i = 1; i <= n; i++) printf("%lld ", d[i] == 1e18 ? -1 : d[i]);
  return 0;
}
