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

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

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

d = A("d")
n = B("n")
h = C("h")

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

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

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

d = A("d")
n = B("n")
h = C("h")

d.w = n
d.s = h
n.u = d
n.w = h
n.s = h
h.s = d
assert h.s.s.s.txt == "d"