#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m, s;
int is[4 * maxn], os[4 * maxn];
struct E {
  int to, next, w;
} edge[40 * maxn];
int head[10 * maxn], ec;
inline void ade(int u, int v, int w) {
  edge[++ec].to = v;
  edge[ec].w = w;
  edge[ec].next = head[u];
  head[u] = ec;
}
int nc = 2;
void build(int k, int u, int v, int l, int r) {
  is[k] = u, os[k] = v;
  ade(u, v, 0);
  if (l == r) return;
  int mid = (l + r) >> 1;
  int x = ++nc, y = ++nc;
  build(k * 2, x, y, l, mid);
  ade(u, x, 0);
  ade(y, v, 0);
  x = ++nc, y = ++nc;
  build(k * 2 + 1, x, y, mid + 1, r);
  ade(u, x, 0);
  ade(y, v, 0);
}
void addout(int k, int l, int r, int L, int R, int p, int v) {
  if (L <= l && r <= R) {
    ade(os[k], p, v);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) addout(k * 2, l, mid, L, R, p, v);
  if (mid < R) addout(k * 2 + 1, mid + 1, r, L, R, p, v);
}
void addin(int k, int l, int r, int L, int R, int p, int v) {
  if (L <= l && r <= R) {
    ade(p, is[k], v);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) addin(k * 2, l, mid, L, R, p, v);
  if (mid < R) addin(k * 2 + 1, mid + 1, r, L, R, p, v);
}
int findpos(int k, int l, int r, int p) {
  if (l == r) return is[k];
  int mid = (l + r) >> 1;
  if (p <= mid) return findpos(k * 2, l, mid, p);
  return findpos(k * 2 + 1, mid + 1, r, p);
}
unsigned long long int dis[10 * maxn];
bool vis[10 * maxn];
inline void dij() {
  int S = findpos(1, 1, n, s);
  priority_queue<pair<unsigned long long int, int>,
                 vector<pair<unsigned long long int, int> >,
                 greater<pair<unsigned long long int, int> > >
      q;
  for (register int i = (1); i <= (nc); i++) dis[i] = 1926081771806291LL;
  dis[S] = 0;
  q.push((pair<unsigned long long int, int>){0, S});
  while (q.size()) {
    int u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (register int i = head[u]; i; i = edge[i].next) {
      int v = edge[i].to;
      if (!vis[v] && dis[u] + edge[i].w < dis[v]) {
        dis[v] = dis[u] + edge[i].w;
        q.push((pair<unsigned long long int, int>){dis[v], v});
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  build(1, 1, 2, 1, n);
  for (register int i = (1); i <= (m); i++) {
    int o;
    scanf("%d", &o);
    if (o == 1) {
      int v, u, w;
      scanf("%d%d%d", &v, &u, &w);
      addout(1, 1, n, v, v, ++nc, 0);
      addin(1, 1, n, u, u, nc, w);
    } else if (o == 2) {
      int v, l, r, w;
      scanf("%d%d%d%d", &v, &l, &r, &w);
      addout(1, 1, n, v, v, ++nc, w);
      addin(1, 1, n, l, r, nc, 0);
    } else {
      int v, l, r, w;
      scanf("%d%d%d%d", &v, &l, &r, &w);
      addout(1, 1, n, l, r, ++nc, 0);
      addin(1, 1, n, v, v, nc, w);
    }
  }
  dij();
  for (register int i = (1); i <= (n); i++) {
    int j = findpos(1, 1, n, i);
    printf("%lld ", dis[j] == 1926081771806291LL ? -1 : dis[j]);
  }
  return 0;
}
