#include <bits/stdc++.h>
using namespace std;
// c++ short types
#define vt vector
//typedef long long ll;
typedef long double ld;
void whattime() { cout << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; }
const int64_t inf = 1e18;
const int mod = 998244353;
bool debug = false;
const ld eps = 1e-9;
mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
string dir = "URDL";
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
void solve() {
int n;
int64_t T;
cin >> n >> T;
vt<int> x(n), y(n);
vt<char> c(n);
map<pair<int, int>, int> ids;
map<int, vt<pair<int, int>>> x_line;
map<int, vt<pair<int, int>>> y_line;
for(int i = 0; i < n; ++i) {
cin >> x[i] >> y[i] >> c[i];
ids[make_pair(x[i], y[i])] = i;
x_line[x[i]].push_back(make_pair(y[i], i));
y_line[y[i]].push_back(make_pair(x[i], i));
}
vt<vt<int>> g(n);
for(auto &zz: x_line) {
auto &v = zz.second;
sort(v.begin(), v.end());
for(int i = 0; i + 1 < int(v.size()); ++i) {
g[v[i].second].push_back(v[i+1].second);
g[v[i+1].second].push_back(v[i].second);
}
}
for(auto &zz: y_line) {
auto &v = zz.second;
sort(v.begin(), v.end());
for(int i = 0; i + 1 < int(v.size()); ++i) {
g[v[i].second].push_back(v[i+1].second);
g[v[i+1].second].push_back(v[i].second);
}
}
auto get_id = [&](char c) {
for(int i = 0; i < 4; ++i) if(dir[i] == c) {
return i;
}
assert(false);
return -1;
};
auto is_ok = [&](int x, int y, int nx, int ny, int type) {
int dxx = nx - x, dyy = ny - y;
if(dxx + dyy == 0) {
return true;
}
// string dir = "URDL";
int ztype = 0;
if(dyy > 0) {
ztype = 0;
} else if(dxx > 0) {
ztype = 1;
} else if(dyy < 0) {
ztype = 2;
} else if(dxx < 0) {
ztype = 3;
}
return ztype == type;
};
vt<vt<int64_t>> dp(n, vt<int64_t>(4, inf));
dp[0][get_id(c[0])] = 0;
set<pair<int64_t, pair<int, int>>> st;
st.insert(make_pair(0ll, make_pair(0, get_id(c[0]))));
while(not st.empty()) {
auto u = st.begin()->second;
int e = u.first, type = u.second;
st.erase(st.begin());
for(auto to: g[e]) if(is_ok(x[e], y[e], x[to], y[to], type)) {
int delta = abs(x[e]-x[to]) + abs(y[e]-y[to]);
if(delta + dp[e][type] < dp[to][type]) {
st.erase(make_pair(dp[to][type], make_pair(to, type)));
st.insert(make_pair(dp[to][type] = delta + dp[e][type], make_pair(to, type)));
}
}
int cur_id = get_id(c[e]);
if(dp[e][cur_id] > dp[e][type]) {
st.erase(make_pair(dp[e][cur_id], make_pair(e, cur_id)));
st.insert(make_pair(dp[e][cur_id] = dp[e][type], make_pair(e, cur_id)));
}
}
for(int i = 0; i < n; ++i) {
int64_t time = *min_element(dp[i].begin(), dp[i].end());
int64_t resx = x[i], resy = y[i];
int type = get_id(c[i]);
int64_t dtime = max(0ll, T - time);
resx += dtime * dx[type];
resy += dtime * dy[type];
cout << resx << ' ' << resy << '\n';
}
}
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
int tt = 1;
if(debug) {
tt = 1e5;
} else {
// cin >> tt;
}
for(int t = 0; t < tt; ++t) {
solve();
}
return 0;
}