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

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

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

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

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

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

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