#include <bits/stdc++.h>
using namespace std;
const int maxn = 6e5 + 10;
int n, q, s;
int rts, num[2][maxn], vis[maxn];
long long dist[maxn];
vector<pair<int, long long> > G[maxn];
void build(int l, int r, int o, int x) {
  rts++;
  num[x][o] = rts;
  if (l == r) {
    if (x == 0)
      G[num[x][o]].push_back({l, 0});
    else
      G[l].push_back({num[x][o], 0});
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, o * 2, x);
  build(mid + 1, r, o * 2 + 1, x);
  if (x == 0) {
    G[num[x][o]].push_back({num[x][o * 2], 0});
    G[num[x][o]].push_back({num[x][o * 2 + 1], 0});
  } else {
    G[num[x][o * 2]].push_back({num[x][o], 0});
    G[num[x][o * 2 + 1]].push_back({num[x][o], 0});
  }
}
void update(int fr, int L, int R, int l, int r, int o, int x, long long w) {
  if (L <= l && r <= R) {
    if (x == 0) {
      G[fr].push_back({num[x][o], w});
    } else {
      G[num[x][o]].push_back({fr, w});
    }
    return;
  }
  int mid = (l + r) / 2;
  if (L <= mid) update(fr, L, R, l, mid, o * 2, x, w);
  if (R > mid) update(fr, L, R, mid + 1, r, o * 2 + 1, x, w);
}
void spfa() {
  queue<int> Q;
  Q.push(s);
  vis[s] = 1;
  dist[s] = 0;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    vis[u] = 0;
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i].first;
      long long w = G[u][i].second;
      if (dist[v] == -1 || dist[v] > dist[u] + w) {
        dist[v] = dist[u] + w;
        if (!vis[v]) {
          Q.push(v);
          vis[v] = 1;
        }
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &q, &s);
  rts = n;
  memset(vis, 0, sizeof(vis));
  memset(dist, -1, sizeof(dist));
  build(1, n, 1, 0);
  build(1, n, 1, 1);
  int t, u, v, l, r, w;
  for (int i = 0; i < q; i++) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%d%I64d", &u, &v, &w);
      G[u].push_back({v, w});
    } else if (t == 2) {
      scanf("%d%d%d%I64d", &u, &l, &r, &w);
      update(u, l, r, 1, n, 1, 0, w);
    } else {
      scanf("%d%d%d%I64d", &u, &l, &r, &w);
      update(u, l, r, 1, n, 1, 1, w);
    }
  }
  spfa();
  for (int i = 1; i <= n; i++) printf("%I64d ", dist[i]);
  return 0;
}
