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

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

m = A("m")
a = B("a")
g = A("g")
h = A("h")
b = B("b")
d = A("d")
c = A("c")
j = A("j")
f = A("f")

m.w = a
a.o = b
g.w = a
h.w = b
b.o = a
d.w = b
c.w = a
j.w = b
f.w = b
assert f.w.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

m = A("m")
a = B("a")
g = A("g")
h = A("h")
b = B("b")
d = A("d")
c = A("c")
j = A("j")
f = A("f")

m.w = a
a.o = b
g.w = a
h.w = b
b.o = a
d.w = b
c.w = a
j.w = b
f.w = b
assert f.w.o.o.o.o.o.txt == "a"