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

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

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

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

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

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

f.o = d
f.z = d
j.q = f
d.q = f
assert f.o.q.o.txt == "d"