#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, q;
long long D[3][N * 4];
bool M[3][N * 4];
vector<pair<int, pair<int, int> > > seg[3][N * 4];
priority_queue<pair<long long, pair<int, int> > > P;
void Build(int id = 1, int l = 1, int r = n + 1) {
  if (r - l == 1) {
    seg[1][id].push_back({0, {l, 0}});
    seg[0][l].push_back({1, {id, 0}});
    seg[2][id].push_back({0, {l, 0}});
    seg[0][l].push_back({2, {id, 0}});
    return;
  }
  Build(id * 2, l, (l + r) / 2);
  Build(id * 2 + 1, (l + r) / 2, r);
  seg[1][id].push_back({1, {id * 2, 0}});
  seg[1][id].push_back({1, {id * 2 + 1, 0}});
  seg[2][id * 2].push_back({2, {id, 0}});
  seg[2][id * 2 + 1].push_back({2, {id, 0}});
}
void Add(int tp, int v, int le, int ri, int w, int id = 1, int l = 1,
         int r = n + 1) {
  if (le >= r || ri <= l) return;
  if (le <= l && r <= ri) {
    if (tp == 2)
      seg[0][v].push_back({1, {id, w}});
    else
      seg[2][id].push_back({0, {v, w}});
    return;
  }
  Add(tp, v, le, ri, w, id * 2, l, (l + r) / 2);
  Add(tp, v, le, ri, w, id * 2 + 1, (l + r) / 2, r);
}
int main() {
  int tp, l, r, v, p, w, st;
  scanf("%d%d%d", &n, &q, &st);
  for (int i = 0; i < q; i++) {
    scanf("%d", &tp);
    if (tp == 1) {
      scanf("%d%d%d", &v, &p, &w);
      seg[0][v].push_back({0, {p, w}});
      continue;
    }
    scanf("%d%d%d%d", &v, &l, &r, &w);
    Add(tp, v, l, r + 1, w);
  }
  Build();
  for (int i = 0; i < 4 * N; i++) D[0][i] = D[1][i] = D[2][i] = 1e18;
  D[0][st] = 0;
  P.push({0, {0, st}});
  while (P.size() > 0) {
    auto pr = P.top();
    P.pop();
    tp = pr.second.first;
    v = pr.second.second;
    if (M[tp][v]) continue;
    M[tp][v] = 1;
    for (auto X : seg[tp][v])
      if (D[X.first][X.second.first] > D[tp][v] + X.second.second) {
        D[X.first][X.second.first] = D[tp][v] + X.second.second;
        P.push({-D[X.first][X.second.first], {X.first, X.second.first}});
      }
  }
  for (int i = 1; i <= n; i++) {
    if (D[0][i] == 1e18) D[0][i] = -1;
    printf("%I64d ", D[0][i]);
  }
  return (0);
}
