func readIntList() -> [String] {
    return readLine()!.split(separator: " ").map{String($0)}
}

func readInt() -> Int {
    return Int(readLine()!)!
}

enum Direction: String {
    case up = "U"
    case right = "R"
    case down = "D"
    case left = "L"
    func rotate(r: Int) -> Self {
        let list: [String] = ["U", "R", "D", "L"]
        let new_index = (list.firstIndex(of: self.rawValue)! + r) % 4
        return Self(rawValue: list[new_index])!
    }
}

struct IthPlane {
    let x: Int
    let y: Int
    let u: Direction
}

func main() {
    let n = readInt()
    var listOfPlane = [IthPlane]()
    for _ in 0...n-1 {
        let line = readIntList()
        listOfPlane.append(IthPlane(x: Int(line[0])!, y: Int(line[1])!, u: Direction(rawValue: line[2])!))
    }
    func crushFinder(a: IthPlane, b: IthPlane) -> Int? {
        func all(a:IthPlane, b: IthPlane) -> Int? {
            if b.u == Direction.down, a.x == b.x, a.y < b.y {
                return (b.y - a.y) * 5
            } else if b.u == Direction.right, b.y - a.y > 0, -(b.x - a.x) == b.y - a.y {
                return (b.y - a.y) * 10
            } else if b.u == Direction.left, b.y - a.y > 0, b.x - a.x == b.y - a.y {
                return (b.y - a.y) * 10
            } else {
                return nil
            }
        }
        switch a.u {
        case Direction.up:
            return all(a: a, b: b)
        case Direction.right:
            let new_a = IthPlane(x: a.y, y: -a.x, u: a.u.rotate(r: 1))
            let new_b = IthPlane(x: b.y, y: -b.x, u: b.u.rotate(r: 1))
            return all(a: new_a, b: new_b)
        case Direction.down:
            let new_a = IthPlane(x: -a.x, y: -a.y, u: a.u.rotate(r: 2))
            let new_b = IthPlane(x: -b.x, y: -b.y, u: b.u.rotate(r: 2))
            return all(a: new_a, b: new_b)
        case Direction.left:
            let new_a = IthPlane(x: -a.y, y: a.x, u: a.u.rotate(r: 3))
            let new_b = IthPlane(x: -b.y, y: b.x, u: b.u.rotate(r: 3))
            return all(a: new_a, b: new_b)
        }
    }
    var crushTime: Int!
    for i in 0...n-1 {
        for j in i...n-1 {
            if let time = crushFinder(a: listOfPlane[i], b: listOfPlane[j]) {
                crushTime = time
            }
        }
    }
    print(crushTime ?? "SAFE")
}

main()
