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

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

enum Direction: String {
    case u = "U"
    case r = "R"
    case d = "D"
    case l = "L"
}

struct IthPlane {
    let x: Int
    let y: Int
    let u: Direction
    init(list: [String]) {
        self.x = Int(list[0])!
        self.y = Int(list[1])!
        self.u = Direction(rawValue: list[2])!
    }
}

func main() {
    let n = readInt()
    var listOfPlane = [IthPlane]()
    for _ in 0...n-1 {
        let line = readIntList()
        listOfPlane.append(IthPlane(list: line))
    }
    func crushFinder(a: IthPlane, b: IthPlane) -> Int? {
        switch a.u {
        case Direction.u:
            if b.u == Direction.d, a.x == b.x, a.y < b.y {
                return (b.y - a.y) * 10
            } else {
                return nil
            }
        case Direction.r:
            if b.u == Direction.l, a.y == b.y, a.x < b.x {
                return (b.x - a.x) * 10
            } else {
                return nil
            }
        case Direction.d:
            if b.u == Direction.u, a.x == b.x, a.y > b.y {
                return (a.y - b.y) * 10
            } else {
                return nil
            }
        case Direction.l:
            if b.u == Direction.r, a.y == b.y, a.x > b.x {
                return (a.x - b.x) * 10
            } else {
                return nil
            }
        }
    }
    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()
