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

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

l = A("l")
j = B("j")
f = A("f")

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

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

l = A("l")
j = B("j")
f = A("f")

l.z = j
l.o = j
j.z = f
f.z = j
f.o = j
assert j.z.o.z.txt == "f"