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

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

d = A("d")
h = B("h")
g = B("g")

d.z = h
h.s = d
h.u = d
g.s = d
g.u = d
assert h.s.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

d = A("d")
h = B("h")
g = B("g")

d.z = h
h.s = d
h.u = d
g.s = d
g.u = d
assert h.s.z.s.txt == "d"