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

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

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

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

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

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

d.z = f
d.w = f
f.q = d
f.y = l
l.q = d
l.y = f
assert d.w.y.q.txt == "d"