#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
struct edge {
  int to, next, w;
} e[MAXN * 20];
int head[MAXN * 4];
int ecnt;
void adde(int u, int v, int w) {
  e[ecnt].to = v;
  e[ecnt].w = w;
  e[ecnt].next = head[u];
  head[u] = ecnt++;
}
struct node {
  int lson, rson;
} tree[MAXN * 4];
int ncnt;
void buildin(int l, int r, int& rt) {
  if (l == r) {
    rt = l;
    return;
  }
  rt = ++ncnt;
  int mid = (l + r) >> 1;
  buildin(l, mid, tree[rt].lson);
  buildin(mid + 1, r, tree[rt].rson);
  adde(rt, tree[rt].lson, 0);
  adde(rt, tree[rt].rson, 0);
}
void buildout(int l, int r, int& rt) {
  if (l == r) {
    rt = l;
    return;
  }
  rt = ++ncnt;
  int mid = (l + r) >> 1;
  buildout(l, mid, tree[rt].lson);
  buildout(mid + 1, r, tree[rt].rson);
  adde(tree[rt].lson, rt, 0);
  adde(tree[rt].rson, rt, 0);
}
void updatein(int v, int L, int R, int w, int l, int r, int rt) {
  if (L <= l && r <= R) {
    adde(v, rt, w);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) {
    updatein(v, L, R, w, l, mid, tree[rt].lson);
  }
  if (R > mid) {
    updatein(v, L, R, w, mid + 1, r, tree[rt].rson);
  }
}
void updateout(int L, int R, int v, int w, int l, int r, int rt) {
  if (L <= l && r <= R) {
    adde(rt, v, w);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) {
    updateout(L, R, v, w, l, mid, tree[rt].lson);
  }
  if (R > mid) {
    updateout(L, R, v, w, mid + 1, r, tree[rt].rson);
  }
}
long long dis[MAXN * 4];
queue<int> que;
void spfa(int s) {
  memset(dis, INF, sizeof dis);
  dis[s] = 0;
  que.push(s);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    for (int i = head[u]; i != -1; i = e[i].next) {
      int v = e[i].to;
      if (dis[v] > dis[u] + e[i].w) {
        dis[v] = dis[u] + e[i].w;
        que.push(v);
      }
    }
  }
}
inline int read() {
  int X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    X = (X << 3) + (X << 1) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -X : X;
}
int main() {
  int n, q, s;
  n = read();
  q = read();
  s = read();
  ncnt = n;
  int rootin, rootout;
  memset(head, -1, sizeof head);
  buildin(1, n, rootin);
  buildout(1, n, rootout);
  for (int i = 1; i <= q; i++) {
    int opr, l, r, u, v, w;
    opr = read();
    switch (opr) {
      case 1:
        u = read();
        v = read();
        w = read();
        adde(u, v, w);
        break;
      case 2:
        u = read();
        l = read();
        r = read();
        w = read();
        updatein(u, l, r, w, 1, n, rootin);
        break;
      case 3:
        u = read();
        l = read();
        r = read();
        w = read();
        updateout(l, r, u, w, 1, n, rootout);
        break;
    }
  }
  spfa(s);
  for (int i = 1; i <= n; i++) {
    cout << ((dis[i] == INF) ? -1 : dis[i]) << " ";
  }
  cout << endl;
}
