#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 2;
const long long inf = 1e17 + 2;
struct node {
  long long idx, lef, rig;
} it[4 * N];
vector<pair<long long, long long> > adj[4 * N];
long long n, dis[4 * N], now;
bool used[4 * N];
priority_queue<pair<long long, long long> > lis;
long long build_it(long long l, long long r) {
  now++;
  long long i = now;
  if (l == r) {
    adj[i].push_back({l, 0});
    return l;
  }
  it[i].lef = build_it(l, (l + r) / 2);
  it[i].rig = build_it((l + r) / 2 + 1, r);
  adj[i].push_back({it[i].lef, 0});
  adj[i].push_back({it[i].rig, 0});
  return i;
}
long long build_it1(long long l, long long r) {
  now++;
  long long i = now;
  if (l == r) {
    adj[l].push_back({i, 0});
    return l;
  }
  it[i].lef = build_it1(l, (l + r) / 2);
  it[i].rig = build_it1((l + r) / 2 + 1, r);
  adj[it[i].lef].push_back({i, 0});
  adj[it[i].rig].push_back({i, 0});
  return i;
}
void addEdge1(long long idx, long long l, long long r, long long lef,
              long long rig, long long to, long long val) {
  if (l > rig || r < lef) {
    return;
  }
  if (l >= lef && r <= rig) {
    adj[idx].push_back({to, val});
    return;
  }
  addEdge1(it[idx].lef, l, (l + r) / 2, lef, rig, to, val);
  addEdge1(it[idx].rig, (l + r) / 2 + 1, r, lef, rig, to, val);
}
void addEdge2(long long idx, long long l, long long r, long long lef,
              long long rig, long long from, long long val) {
  if (l > rig || r < lef) {
    return;
  }
  if (l >= lef && r <= rig) {
    adj[from].push_back({idx, val});
    return;
  }
  addEdge2(it[idx].lef, l, (l + r) / 2, lef, rig, from, val);
  addEdge2(it[idx].rig, (l + r) / 2 + 1, r, lef, rig, from, val);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long i, j, k, l, s, m, num, z, q, num1;
  cin >> n >> q >> s;
  now = n;
  num = build_it(1, n);
  num1 = build_it1(1, n);
  for (i = 1; i <= q; i++) {
    cin >> j;
    if (j == 1) {
      cin >> k >> l >> m;
      addEdge2(num, 1, n, l, l, k, m);
    }
    if (j == 2) {
      cin >> k >> l >> m >> z;
      addEdge2(num, 1, n, l, m, k, z);
    }
    if (j == 3) {
      cin >> k >> l >> m >> z;
      addEdge1(num1, 1, n, l, m, k, z);
    }
  }
  for (i = 1; i <= now; i++) {
    dis[i] = inf;
  }
  dis[s] = 0;
  lis.push({-dis[s], s});
  while (lis.size()) {
    k = lis.top().first;
    j = lis.top().second;
    lis.pop();
    if (!used[j] && -k == dis[j]) {
      used[j] = true;
      for (l = 0; l < adj[j].size(); l++) {
        if (dis[adj[j][l].first] > dis[j] + adj[j][l].second) {
          dis[adj[j][l].first] = dis[j] + adj[j][l].second;
          lis.push({-dis[adj[j][l].first], adj[j][l].first});
        }
      }
    }
  }
  for (i = 1; i <= n; i++) {
    if (used[i]) {
      cout << dis[i] << ' ';
    } else {
      cout << "-1 ";
    }
  }
}
