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

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

d = A("d")
a = B("a")
j = B("j")

d.z = a
a.z = j
a.t = j
j.z = a
j.t = a
assert j.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.z: B = None
        self.t: B = None
        self.txt = txt

d = A("d")
a = B("a")
j = B("j")

d.z = a
a.z = j
a.t = j
j.z = a
j.t = a
assert j.t.z.t.txt == "a"