class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: B = None
        self.txt = txt

g = A("g")
n = B("n")
l = B("l")
b = A("b")
m = A("m")
h = B("h")
i = A("i")

g.y = m
n.t = l
n.r = h
l.t = n
l.r = n
b.y = g
m.y = i
h.t = n
h.r = n
i.y = g
assert g.y.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: B = None
        self.txt = txt

g = A("g")
n = B("n")
l = B("l")
b = A("b")
m = A("m")
h = B("h")
i = A("i")

g.y = m
n.t = l
n.r = h
l.t = n
l.r = n
b.y = g
m.y = i
h.t = n
h.r = n
i.y = g
assert g.y.y.y.y.y.y.y.txt == "m"