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

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

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

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

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

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

f.z = g
a.t = d
d.z = a
g.t = f
assert f.z.t.z.t.txt == "f"