#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const long long INF = 1e17 + 10;
bool book[maxn << 4];
long long dis[maxn << 4];
int head[maxn << 2], tot, n, q, s, id, vis1[maxn << 1], vis2[maxn << 1];
struct Node {
  int u, v, w, next;
  Node(int _u = 0, int _v = 0, int _w = 0, int _next = 0)
      : u(_u), v(_v), w(_w), next(_next) {}
} edges[maxn << 4];
struct node {
  int v;
  long long d;
  node(int _v = 0, long long _d = 0) : v(_v), d(_d) {}
  bool operator<(const node& x) const { return d > x.d; }
};
void addedge(int u, int v, int w) {
  edges[tot] = Node(u, v, w, head[u]);
  head[u] = tot++;
}
void buildtree1(int rt, int l, int r) {
  if (vis1[rt] == 0) vis1[rt] = ++id;
  if (l == r) {
    addedge(vis1[rt], l, 0);
    return;
  }
  int mid = (l + r) >> 1, lson = rt << 1, rson = rt << 1 | 1;
  buildtree1(lson, l, mid);
  buildtree1(rson, mid + 1, r);
  addedge(vis1[rt], vis1[lson], 0);
  addedge(vis1[rt], vis1[rson], 0);
}
void buildtree2(int rt, int l, int r) {
  if (vis2[rt] == 0) vis2[rt] = ++id;
  if (l == r) {
    addedge(l, vis2[rt], 0);
    return;
  }
  int mid = (l + r) >> 1, lson = rt << 1, rson = rt << 1 | 1;
  buildtree2(lson, l, mid);
  buildtree2(rson, mid + 1, r);
  addedge(vis2[lson], vis2[rt], 0);
  addedge(vis2[rson], vis2[rt], 0);
}
void addedge2(int u, int rt, int l, int r, int ql, int qr, int w) {
  if (l > qr || r < ql) return;
  if (ql <= l && r <= qr) {
    addedge(vis2[rt], u, w);
    return;
  }
  int mid = (l + r) >> 1, lson = rt << 1, rson = rt << 1 | 1;
  addedge2(u, lson, l, mid, ql, qr, w);
  addedge2(u, rson, mid + 1, r, ql, qr, w);
}
void addedge1(int u, int rt, int l, int r, int ql, int qr, int w) {
  if (l > qr || r < ql) return;
  if (ql <= l && r <= qr) {
    addedge(u, vis1[rt], w);
    return;
  }
  int mid = (l + r) >> 1, lson = rt << 1, rson = rt << 1 | 1;
  addedge1(u, lson, l, mid, ql, qr, w);
  addedge1(u, rson, mid + 1, r, ql, qr, w);
}
void init() {
  id = n;
  tot = 0;
  memset(vis1, 0, sizeof(vis1));
  memset(vis2, 0, sizeof(vis2));
  memset(book, false, sizeof(book));
  memset(head, -1, sizeof(head));
  buildtree1(1, 1, n);
  buildtree2(1, 1, n);
}
void dijkstra() {
  priority_queue<node> Q;
  for (int i = 0; i <= 9 * n; i++) {
    dis[i] = INF;
  }
  dis[s] = 0;
  Q.push(node(s, 0));
  while (!Q.empty()) {
    node a = Q.top();
    Q.pop();
    int u = a.v;
    if (book[u]) continue;
    book[u] = true;
    for (int i = head[u]; ~i; i = edges[i].next) {
      int v = edges[i].v, w = edges[i].w;
      if (dis[u] + w < dis[v]) {
        dis[v] = dis[u] + w;
        if (!book[v]) Q.push(node(v, dis[v]));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dis[i] == INF) dis[i] = -1;
    if (i == 1)
      cout << dis[i];
    else
      cout << " " << dis[i];
  }
  puts("");
}
int main() {
  int op, u, v, w, l, r;
  while (~scanf("%d%d%d", &n, &q, &s)) {
    init();
    while (q--) {
      scanf("%d", &op);
      if (op == 1) {
        scanf("%d%d%d", &u, &v, &w);
        addedge(u, v, w);
      } else if (op == 2) {
        scanf("%d%d%d%d", &u, &l, &r, &w);
        addedge1(u, 1, 1, n, l, r, w);
      } else {
        scanf("%d%d%d%d", &u, &l, &r, &w);
        addedge2(u, 1, 1, n, l, r, w);
      }
    }
    dijkstra();
  }
}
