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

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

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

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

m.s = f
m.p = j
b.u = h
k.y = c
k.u = f
a.u = h
c.u = h
h.y = b
h.u = j
f.s = j
f.p = j
j.s = m
j.p = m
assert j.s.s.s.s.s.p.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.p: A = None
        self.txt = txt

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

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

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

m.s = f
m.p = j
b.u = h
k.y = c
k.u = f
a.u = h
c.u = h
h.y = b
h.u = j
f.s = j
f.p = j
j.s = m
j.p = m
assert j.s.s.s.s.s.p.p.s.txt == "f"