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

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

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

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

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

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

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