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

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

h = A("h")
c = B("c")
i = A("i")
g = A("g")
l = B("l")
m = B("m")
f = B("f")

h.t = i
h.w = f
c.o = m
i.t = h
i.w = c
g.t = h
g.w = m
l.o = m
m.o = l
f.o = m
assert l.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.w: B = None
        self.txt = txt

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

h = A("h")
c = B("c")
i = A("i")
g = A("g")
l = B("l")
m = B("m")
f = B("f")

h.t = i
h.w = f
c.o = m
i.t = h
i.w = c
g.t = h
g.w = m
l.o = m
m.o = l
f.o = m
assert l.o.o.o.o.o.txt == "m"