#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5;
const long long Inf = 1LL << 60;
long long dis[8 * MaxN + 5];
vector<pair<long long, int> > G[8 * MaxN + 5];
int mp[MaxN + 5];
bool vis[8 * MaxN + 5];
pair<long long, int> nxt;
void build(int now, int l, int r) {
  vis[now] = vis[now + 4 * MaxN] = true;
  dis[now] = dis[now + 4 * MaxN] = Inf;
  if (l == r) {
    mp[l] = now;
    nxt.second = now + 4 * MaxN;
    G[now].push_back(nxt);
    nxt.second = now;
    G[now + 4 * MaxN].push_back(nxt);
    return;
  }
  nxt.second = now << 1;
  G[now].push_back(nxt);
  nxt.second = now << 1 | 1;
  G[now].push_back(nxt);
  nxt.second = now + 4 * MaxN;
  G[(now << 1) + 4 * MaxN].push_back(nxt);
  G[(now << 1 | 1) + 4 * MaxN].push_back(nxt);
  build(now << 1, l, (l + r) >> 1);
  build(now << 1 | 1, ((l + r) >> 1) + 1, r);
  return;
}
void Gonxt(int now, int l, int r, int dl, int dr, int m, int flag) {
  if (dl == l && dr == r) {
    if (flag == 2) {
      nxt.second = now;
      G[m].push_back(nxt);
    } else
      G[now + 4 * MaxN].push_back(nxt);
    return;
  }
  int mid = (l + r) >> 1;
  if (dl <= mid) Gonxt(now << 1, l, mid, dl, min(dr, mid), m, flag);
  if (mid < dr) Gonxt(now << 1 | 1, mid + 1, r, max(dl, mid + 1), dr, m, flag);
  return;
}
struct cmp {
  bool operator()(pair<long long, int> A, pair<long long, int> B) {
    return A.first > B.first;
  }
};
int main() {
  int op, l, r, u, n, q, second, Size;
  scanf("%d %d %d", &n, &q, &second);
  nxt.first = 0LL;
  build(1, 1, n);
  while (q--) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d %d %lld", &u, &nxt.second, &nxt.first);
      nxt.second = mp[nxt.second];
      G[mp[u]].push_back(nxt);
    } else if (op == 2) {
      scanf("%d %d %d %lld", &u, &l, &r, &nxt.first);
      u = mp[u];
      Gonxt(1, 1, n, l, r, u, 2);
    } else {
      scanf("%d %d %d %lld", &u, &l, &r, &nxt.first);
      nxt.second = mp[u];
      Gonxt(1, 1, n, l, r, u, 3);
    }
  }
  priority_queue<pair<long long, int>, vector<pair<long long, int> >, cmp> que;
  while (!que.empty()) que.pop();
  nxt.first = 0LL, nxt.second = mp[second];
  dis[nxt.second] = 0LL;
  que.push(nxt);
  pair<long long, int> now;
  while (!que.empty()) {
    now = que.top();
    que.pop();
    if (vis[now.second]) {
      vis[now.second] = false;
      Size = G[now.second].size();
      for (int i = 0; i < Size; i++) {
        nxt = G[now.second][i];
        if (vis[nxt.second] && dis[nxt.second] > now.first + nxt.first) {
          dis[nxt.second] = now.first + nxt.first;
          nxt.first = dis[nxt.second];
          que.push(nxt);
        }
      }
    }
  }
  for (int i = 1; i < n; i++)
    printf("%lld ", dis[mp[i]] == Inf ? -1 : dis[mp[i]]);
  printf("%lld\n", dis[mp[n]] == Inf ? -1 : dis[mp[n]]);
  return 0;
}
