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

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

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

k = A("k")
h = B("h")
m = C("m")
j = B("j")
d = A("d")

k.s = d
h.t = m
h.z = j
m.p = k
j.t = m
j.z = h
d.s = k
assert k.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

k = A("k")
h = B("h")
m = C("m")
j = B("j")
d = A("d")

k.s = d
h.t = m
h.z = j
m.p = k
j.t = m
j.z = h
d.s = k
assert k.s.s.s.s.s.txt == "d"