n = gets.to_i
x_hash = {}
y_hash = {}
xy_hash = {} # key: x-y
arr = n.times.map do
  x, y, u = gets.split(" ")
  x = x.to_i
  y = y.to_i
  if u == "U" || u == "D"
    x_hash[x] ||= []
    x_hash[x] << [y, u] 
  else
    y_hash[y] ||= []
    y_hash[y] << [x, u]
  end
  xy_hash[x - y] ||= { "UR" => [], "DL" => [] }
  if u == "U" || u == "R"
    key = "UR"
  else
    key = "DL"
  end
  xy_hash[x - y][key] << [x, y, u]
end

min_sec = 100_000_000_000
x_hash.each do |_x, arr|
  sarr = arr.sort_by{|y, _| y}
  sarr[0...(sarr.length-1)].each_with_index do |(y, u), i|
    ny, nu = sarr[i + 1]
    if u == "U" && nu == "D"
      t = 5 * (y - ny).abs
      min_sec = t if t < min_sec
    end
  end
end
y_hash.each do |_y, arr|
  sarr = arr.sort_by{|x, _| x}
  sarr[0...(sarr.length-1)].each_with_index do |(x, u), i|
    nx, nu = sarr[i + 1]
    if u == "R" && nu == "L"
      t = 5 * (x - nx).abs
      min_sec = t if t < min_sec
    end
  end
end
xy_hash.each do |_diff, hash|
  sarr = hash["UR"].sort_by{|x, y, _| x}
  sarr[0...(sarr.length-1)].each_with_index do |(x, y, u), i|
    nx, ny, nu = sarr[i + 1]
    if u == "R" && nu == "U"
      t = 10 * (x - nx).abs
      min_sec = t if t < min_sec
    end
  end
  sarr = hash["DL"].sort_by{|x, y, _| x}
  sarr[0...(sarr.length-1)].each_with_index do |(x, y, u), i|
    nx, ny, nu = sarr[i + 1]
    if u == "D" && nu == "L"
      t = 10 * (x - nx).abs
      min_sec = t if t < min_sec
    end
  end    
end

puts min_sec == 100_000_000_000 ? "SAFE" : min_sec