#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int man = 2e5 + 10;
template <typename T>
inline T read() {
  T sum = 0, fl = 1;
  int ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fl = -1;
  for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0';
  return sum * fl;
}
template <typename T>
inline void write(T x) {
  static int sta[35];
  int top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
}
template <typename T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T exgcd(T a, T b, T &g, T &x, T &y) {
  if (!b) {
    g = a, x = 1, y = 0;
  } else {
    exgcd(b, a % b, g, y, x);
    y -= x * (a / b);
  }
}
const long long mod = 1e9 + 7;
long long cnt = 0;
struct no {
  long long v, w;
  no(long long v, long long w) {
    this->v = v;
    this->w = w;
  }
};
vector<no> sp[10 * man];
long long tr[man * 10][2];
void add(long long u, long long v, long long w) { sp[u].push_back(no(v, w)); }
void build1(long long &t, long long l, long long r) {
  if (l == r) {
    t = l;
    return;
  }
  t = ++cnt;
  long long m = l + r >> 1;
  build1(tr[t][0], l, m);
  build1(tr[t][1], m + 1, r);
  add(t, tr[t][0], 0);
  add(t, tr[t][1], 0);
}
void build2(long long &t, long long l, long long r) {
  if (l == r) {
    t = l;
    return;
  }
  t = ++cnt;
  long long m = l + r >> 1;
  build2(tr[t][0], l, m);
  build2(tr[t][1], m + 1, r);
  add(tr[t][0], t, 0);
  add(tr[t][1], t, 0);
}
void add(long long t, long long l, long long r, long long L, long long R,
         long long u, long long w, long long op) {
  if (L <= l && r <= R) {
    if (2 == op)
      add(u, t, w);
    else
      add(t, u, w);
    return;
  }
  long long m = l + r >> 1;
  if (L <= m) add(tr[t][0], l, m, L, R, u, w, op);
  if (R > m) add(tr[t][1], m + 1, r, L, R, u, w, op);
}
struct node {
  long long dis;
  long long v;
  node(long long dis = 0, long long v = 0) {
    this->dis = dis;
    this->v = v;
  }
  bool operator<(const node &a) const { return dis > a.dis; }
};
long long dis[man * 10];
long long inf = 0x3f3f3f3f3f3f3f3f;
bool vis[man * 10];
void dij(long long s) {
  memset(dis, 0x3f3f3f3f, sizeof(dis));
  memset(vis, 0, sizeof(vis));
  priority_queue<node> q;
  q.push(node(0, s));
  dis[s] = 0;
  while (q.size()) {
    long long u = q.top().v;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (long long i = 0; i < sp[u].size(); i++) {
      long long v = sp[u][i].v;
      long long w = sp[u][i].w;
      if (!vis[v] && dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        q.push(node(dis[v], v));
      }
    }
  }
}
signed main() {
  long long n, q, s;
  scanf("%lld%lld%lld", &n, &q, &s);
  cnt = n;
  long long rt1, rt2;
  build1(rt1, 1, n);
  build2(rt2, 1, n);
  for (long long i = 1; i <= q; i++) {
    long long u, v, w;
    long long op;
    scanf("%lld", &op);
    if (1 == op) {
      scanf("%lld%lld%lld", &u, &v, &w);
      add(u, v, w);
    } else if (2 == op) {
      long long l, r;
      scanf("%lld%lld%lld%lld", &u, &l, &r, &w);
      add(rt1, 1, n, l, r, u, w, 2);
    } else if (3 == op) {
      long long l, r;
      scanf("%lld%lld%lld%lld", &u, &l, &r, &w);
      add(rt2, 1, n, l, r, u, w, 3);
    }
  }
  dij(s);
  for (long long i = 1; i <= n; i++) {
    printf(i == n ? "%lld\n" : "%lld ", dis[i] == inf ? -1 : dis[i]);
  }
  return 0;
}
