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

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

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

m = A("m")
e = B("e")
d = C("d")
g = A("g")
k = A("k")
c = B("c")
l = A("l")
j = B("j")
n = A("n")
b = C("b")

m.p = d
e.y = b
d.p = e
d.s = c
d.y = b
g.p = b
k.p = d
c.y = d
l.p = b
j.y = b
n.p = b
b.p = c
b.s = c
b.y = d
assert j.y.y.s.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

m = A("m")
e = B("e")
d = C("d")
g = A("g")
k = A("k")
c = B("c")
l = A("l")
j = B("j")
n = A("n")
b = C("b")

m.p = d
e.y = b
d.p = e
d.s = c
d.y = b
g.p = b
k.p = d
c.y = d
l.p = b
j.y = b
n.p = b
b.p = c
b.s = c
b.y = d
assert j.y.y.s.y.txt == "d"