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

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

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

a = A("a")
m = B("m")
d = C("d")
h = C("h")

a.t = m
m.t = a
m.x = a
d.s = a
h.s = a
assert m.x.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

a = A("a")
m = B("m")
d = C("d")
h = C("h")

a.t = m
m.t = a
m.x = a
d.s = a
h.s = a
assert m.x.t.t.txt == "a"