#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 5;
const int N = 1e5 + 5;
struct node {
  int l, r;
  int num;
} ta[N << 2], tb[N << 2];
int pa[N], pb[N];
struct node1 {
  long long w;
  int v;
  node1(long long _w, int _v) : w(_w), v(_v) {}
};
vector<node1> ve[N * 8];
int vis[N * 8];
long long dis[N * 8];
int tot;
void builda(int i, int l, int r) {
  ta[i].l = l;
  ta[i].r = r;
  ta[i].num = ++tot;
  if (ta[i].l == ta[i].r) {
    pa[l] = ta[i].num;
    return;
  }
  int mid = (ta[i].l + ta[i].r) >> 1;
  builda((i << 1), l, mid);
  builda((i << 1 | 1), mid + 1, r);
  ve[ta[(i << 1)].num].push_back(node1(0, ta[i].num));
  ve[ta[(i << 1 | 1)].num].push_back(node1(0, ta[i].num));
}
void updatea(int i, int l, int r, int num, long long w) {
  if (ta[i].l == l && ta[i].r == r) {
    ve[ta[i].num].push_back(node1(w, num));
    return;
  }
  int mid = (ta[i].l + ta[i].r) >> 1;
  if (r <= mid)
    updatea((i << 1), l, r, num, w);
  else if (l > mid)
    updatea((i << 1 | 1), l, r, num, w);
  else {
    updatea((i << 1), l, mid, num, w);
    updatea((i << 1 | 1), mid + 1, r, num, w);
  }
}
void buildb(int i, int l, int r) {
  tb[i].l = l;
  tb[i].r = r;
  tb[i].num = ++tot;
  if (tb[i].l == tb[i].r) {
    pb[l] = tb[i].num;
    ve[tb[i].num].push_back(node1(0, pa[l]));
    return;
  }
  int mid = (tb[i].l + tb[i].r) >> 1;
  buildb((i << 1), l, mid);
  buildb((i << 1 | 1), mid + 1, r);
  ve[tb[i].num].push_back(node1(0, tb[(i << 1)].num));
  ve[tb[i].num].push_back(node1(0, tb[(i << 1 | 1)].num));
}
void updateb(int i, int l, int r, int num, long long w) {
  if (tb[i].l == l && tb[i].r == r) {
    ve[num].push_back(node1(w, tb[i].num));
    return;
  }
  int mid = (tb[i].l + tb[i].r) >> 1;
  if (r <= mid)
    updateb((i << 1), l, r, num, w);
  else if (l > mid)
    updateb((i << 1 | 1), l, r, num, w);
  else {
    updateb((i << 1), l, mid, num, w);
    updateb((i << 1 | 1), mid + 1, r, num, w);
  }
}
int n, m, q, s;
void dij(int st) {
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i <= 8 * n; i++) dis[i] = inf;
  dis[st] = 0;
  pair<long long, int> tmp;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  q.push(pair<long long, int>(0, st));
  int u, v;
  while (!q.empty()) {
    tmp = q.top();
    q.pop();
    u = tmp.second;
    if (tmp.first > dis[u]) continue;
    vis[u] = 1;
    for (int i = 0; i < ve[u].size(); i++) {
      v = ve[u][i].v;
      if (vis[v]) continue;
      if (dis[v] > dis[u] + ve[u][i].w) {
        dis[v] = dis[u] + ve[u][i].w;
        q.push(pair<long long, int>(dis[v], v));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dis[pa[i]] != inf) {
      printf("%lld ", dis[pa[i]]);
    } else
      printf("-1 ");
  }
  return;
}
int main() {
  int op, l, r, u, v;
  long long w;
  scanf("%d %d %d", &n, &m, &s);
  int rta = 1;
  builda(1, 1, n);
  int rtb = 1;
  buildb(rtb, 1, n);
  while (m--) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d %d %lld", &u, &v, &w);
      ve[pa[u]].push_back(node1(w, pb[v]));
    } else if (op == 2) {
      scanf("%d %d %d %lld", &u, &l, &r, &w);
      updateb(rtb, l, r, pa[u], w);
    } else if (op == 3) {
      scanf("%d %d %d %lld", &u, &l, &r, &w);
      updatea(rta, l, r, pb[u], w);
    }
  }
  dij(pa[s]);
  return 0;
}
