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

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

g = A("g")
i = B("i")
e = A("e")
k = B("k")

g.z = e
i.o = e
i.z = g
e.z = g
k.o = e
k.z = e
assert k.o.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

g = A("g")
i = B("i")
e = A("e")
k = B("k")

g.z = e
i.o = e
i.z = g
e.z = g
k.o = e
k.z = e
assert k.o.z.z.txt == "e"