#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
const int maxm = 3000000 + 10;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000000007;
int in[maxn << 2], out[maxn << 2], N;
struct Edge {
  int to, next, w;
  Edge() {}
} edge[maxm];
int head[maxn << 3], tot;
void addedge(int u, int v, int w) {
  edge[tot].to = v;
  edge[tot].w = w;
  edge[tot].next = head[u];
  head[u] = tot++;
}
pair<int, int> a[maxn];
void build(int o, int L, int R) {
  in[o] = N++;
  out[o] = N++;
  if (L == R) {
    addedge(in[o], out[o], 0);
    a[L] = pair<int, int>(in[o], out[o]);
    return;
  }
  int M = L + (R - L) / 2;
  int lc = (o << 1), rc = (o << 1 | 1);
  build(lc, L, M);
  build(rc, M + 1, R);
  addedge(in[o], in[lc], 0);
  addedge(in[o], in[rc], 0);
  addedge(out[lc], out[o], 0);
  addedge(out[rc], out[o], 0);
}
void add1(int o, int L, int R, int ql, int qr, int u, int w) {
  if (ql <= L && R <= qr) {
    addedge(u, in[o], w);
    return;
  }
  int M = L + (R - L) / 2;
  if (ql <= M) add1(o << 1, L, M, ql, qr, u, w);
  if (qr > M) add1(o << 1 | 1, M + 1, R, ql, qr, u, w);
}
void add2(int o, int L, int R, int ql, int qr, int u, int w) {
  if (ql <= L && R <= qr) {
    addedge(out[o], u, w);
    return;
  }
  int M = L + (R - L) / 2;
  if (ql <= M) add2(o << 1, L, M, ql, qr, u, w);
  if (qr > M) add2(o << 1 | 1, M + 1, R, ql, qr, u, w);
}
long long dis[maxn << 3];
struct dijNode {
  int to;
  long long w;
  dijNode(int to, long long w) : to(to), w(w) {}
  bool operator<(const dijNode &rhs) const { return w > rhs.w; }
};
priority_queue<dijNode> q;
bool vis[maxn << 3];
void dij(int S) {
  memset(dis, 0x3f, sizeof(dis));
  dis[S] = 0;
  q.push(dijNode(S, 0));
  while (!q.empty()) {
    dijNode t = q.top();
    q.pop();
    if (vis[t.to]) continue;
    vis[t.to] = true;
    for (int i = head[t.to]; ~i; i = edge[i].next) {
      int v = edge[i].to;
      if (dis[v] > dis[t.to] + edge[i].w) {
        dis[v] = dis[t.to] + edge[i].w;
        q.push(dijNode(v, dis[v]));
      }
    }
  }
}
void output(int o, int L, int R) {
  if (L == R) {
    if (dis[in[o]] < INF)
      cout << dis[in[o]] << " ";
    else
      cout << -1 << " ";
    return;
  }
  int M = L + (R - L) / 2;
  output(o << 1, L, M);
  output(o << 1 | 1, M + 1, R);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(head, -1, sizeof(head));
  int n, q, s;
  cin >> n >> q >> s;
  build(1, 1, n);
  for (int i = 0; i < q; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      int u, v, w;
      cin >> u >> v >> w;
      addedge(a[u].second, a[v].first, w);
    } else if (op == 2) {
      int u, l, r, w;
      cin >> u >> l >> r >> w;
      add1(1, 1, n, l, r, a[u].second, w);
    } else {
      int u, l, r, w;
      cin >> u >> l >> r >> w;
      add2(1, 1, n, l, r, a[u].first, w);
    }
  }
  dij(a[s].first);
  output(1, 1, n);
  return 0;
}
