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

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.s: B = None
        self.txt = txt

a = A("a")
f = B("f")
i = B("i")
d = A("d")

a.z = f
a.w = d
f.t = i
f.s = i
i.t = f
i.s = f
d.z = f
d.w = a
assert i.s.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.w: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.s: B = None
        self.txt = txt

a = A("a")
f = B("f")
i = B("i")
d = A("d")

a.z = f
a.w = d
f.t = i
f.s = i
i.t = f
i.s = f
d.z = f
d.w = a
assert i.s.t.t.txt == "f"