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

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

f = A("f")
g = B("g")
a = B("a")

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

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

f = A("f")
g = B("g")
a = B("a")

f.t = g
f.v = a
g.z = f
g.w = f
a.z = f
a.w = f
assert a.w.v.w.txt == "f"