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

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

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

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

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

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

e.q = f
e.z = d
f.w = e
d.w = e
assert d.w.z.w.txt == "e"