#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const long long inf = 1e18;
vector<pair<int, int> > g[maxn << 2];
int lson[maxn << 2][2];
int rson[maxn << 2][2];
int T[2];
int tot;
int n, q, s;
int build(int l, int r, int x) {
  int rt = ++tot;
  if (l == r) {
    if (x == 0)
      g[rt].push_back(make_pair(l, 0));
    else
      g[l].push_back(make_pair(rt, 0));
    return rt;
  }
  int mid = (l + r) >> 1;
  lson[rt][x] = build(l, mid, x);
  rson[rt][x] = build(mid + 1, r, x);
  if (x == 0) {
    g[rt].push_back(make_pair(lson[rt][x], 0));
    g[rt].push_back(make_pair(rson[rt][x], 0));
  } else {
    g[lson[rt][x]].push_back(make_pair(rt, 0));
    g[rson[rt][x]].push_back(make_pair(rt, 0));
  }
  return rt;
}
void addedge1(int u, int rt, int l, int r, int L, int R, int w) {
  if (l >= L && r <= R) {
    g[u].push_back(make_pair(rt, w));
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) addedge1(u, lson[rt][0], l, mid, L, R, w);
  if (R > mid) addedge1(u, rson[rt][0], mid + 1, r, L, R, w);
}
void addedge2(int u, int rt, int l, int r, int L, int R, int w) {
  if (l >= L && r <= R) {
    g[rt].push_back(make_pair(u, w));
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) addedge2(u, lson[rt][1], l, mid, L, R, w);
  if (R > mid) addedge2(u, rson[rt][1], mid + 1, r, L, R, w);
}
struct qnode {
  int v;
  long long w;
  qnode(int vv, long long ww) {
    v = vv;
    w = ww;
  }
  bool operator<(const qnode &r) const { return w > r.w; }
};
int vis[maxn << 2];
long long d[maxn << 2];
void dij(int s) {
  for (int i = 1; i <= tot; i++) d[i] = inf, vis[i] = 0;
  d[s] = 0;
  priority_queue<qnode> q;
  q.push(qnode(s, d[s]));
  while (q.size()) {
    qnode tt = q.top();
    q.pop();
    int u = tt.v;
    if (vis[u]) continue;
    vis[u] = 1;
    for (auto v : g[u]) {
      if (vis[v.first]) continue;
      if (d[u] + v.second < d[v.first]) {
        d[v.first] = d[u] + v.second;
        q.push(qnode(v.first, d[v.first]));
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &q, &s);
  tot = n;
  T[0] = build(1, n, 0);
  T[1] = build(1, n, 1);
  for (int i = 1; i <= q; i++) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int u, v, w;
      scanf("%d%d%d", &u, &v, &w);
      addedge1(u, T[0], 1, n, v, v, w);
    } else if (op == 2) {
      int u, l, r, w;
      scanf("%d%d%d%d", &u, &l, &r, &w);
      addedge1(u, T[0], 1, n, l, r, w);
    } else if (op == 3) {
      int u, l, r, w;
      scanf("%d%d%d%d", &u, &l, &r, &w);
      addedge2(u, T[1], 1, n, l, r, w);
    }
  }
  dij(s);
  for (int i = 1; i <= n; i++) {
    if (d[i] == inf) d[i] = -1;
    printf("%lld ", d[i]);
  }
}
