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

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

g = A("g")
f = B("f")
e = B("e")
l = B("l")
d = A("d")
m = A("m")

g.z = l
f.o = d
e.o = g
l.o = g
d.z = e
m.z = l
assert g.z.o.z.o.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

g = A("g")
f = B("f")
e = B("e")
l = B("l")
d = A("d")
m = A("m")

g.z = l
f.o = d
e.o = g
l.o = g
d.z = e
m.z = l
assert g.z.o.z.o.z.o.txt == "g"