#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> E[903005];
long long d[903005];
bool inQue[903005];
const int offset2 = 100003;
const int offset3 = 500300;
void build2(int L, int R, int i) {
  if (L == R) {
    E[i + offset2].emplace_back(L, 0);
    return;
  }
  int M = (L + R) / 2;
  build2(L, M, 2 * i);
  E[i + offset2].emplace_back(2 * i + offset2, 0);
  build2(M + 1, R, 2 * i + 1);
  E[i + offset2].emplace_back(2 * i + 1 + offset2, 0);
}
void build3(int L, int R, int i) {
  if (L == R) {
    E[L].emplace_back(i + offset3, 0);
    return;
  }
  int M = (L + R) / 2;
  build3(L, M, 2 * i);
  E[2 * i + offset3].emplace_back(i + offset3, 0);
  build3(M + 1, R, 2 * i + 1);
  E[2 * i + 1 + offset3].emplace_back(i + offset3, 0);
}
void update2(int l, int r, int L, int R, int i, int v, int w) {
  if (l <= L and R <= r) {
    E[v].emplace_back(i + offset2, w);
    return;
  }
  int M = (L + R) / 2;
  if (l <= M) update2(l, r, L, M, 2 * i, v, w);
  if (r > M) update2(l, r, M + 1, R, 2 * i + 1, v, w);
}
void update3(int l, int r, int L, int R, int i, int v, int w) {
  if (l <= L and R <= r) {
    E[i + offset3].emplace_back(v, w);
    return;
  }
  int M = (L + R) / 2;
  if (l <= M) update3(l, r, L, M, 2 * i, v, w);
  if (r > M) update3(l, r, M + 1, R, 2 * i + 1, v, w);
}
void shortestPath(int s) {
  fill(begin(d), end(d), 1e18);
  queue<int> Q;
  Q.push(s);
  d[s] = 0;
  while (!Q.empty()) {
    auto x = Q.front();
    Q.pop();
    inQue[x] = 0;
    for (auto [y, c] : E[x]) {
      if (d[x] + c < d[y]) {
        d[y] = d[x] + c;
        if (!inQue[y]) inQue[y] = 1, Q.push(y);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, q, s;
  cin >> n >> q >> s;
  build2(1, n, 1);
  build3(1, n, 1);
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      int v, u, w;
      cin >> v >> u >> w;
      E[v].emplace_back(u, w);
    } else if (t == 2) {
      int v, l, r, w;
      cin >> v >> l >> r >> w;
      update2(l, r, 1, n, 1, v, w);
    } else {
      int v, l, r, w;
      cin >> v >> l >> r >> w;
      update3(l, r, 1, n, 1, v, w);
    }
  }
  shortestPath(s);
  for (int i = 1; i <= n; ++i) cout << (d[i] == 1e18 ? -1 : d[i]) << ' ';
  cout << endl;
  return 0;
}
