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

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

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

b = A("b")
h = B("h")
n = C("n")
k = B("k")
c = A("c")
m = C("m")
j = A("j")
a = B("a")
d = A("d")

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

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

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

b = A("b")
h = B("h")
n = C("n")
k = B("k")
c = A("c")
m = C("m")
j = A("j")
a = B("a")
d = A("d")

b.p = n
h.t = j
h.s = m
n.t = a
k.t = c
k.s = n
c.p = n
m.t = a
j.p = n
a.t = d
a.s = n
d.p = m
assert j.p.t.t.p.txt == "m"