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

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

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

g = A("g")
d = B("d")
n = C("n")
h = C("h")
f = A("f")
j = A("j")
e = C("e")
c = A("c")
a = C("a")

g.r = d
d.p = c
n.z = j
n.y = d
h.z = j
h.y = d
f.r = d
j.r = d
e.z = c
e.y = d
c.r = d
a.z = g
a.y = d
assert d.p.r.p.r.p.r.p.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

g = A("g")
d = B("d")
n = C("n")
h = C("h")
f = A("f")
j = A("j")
e = C("e")
c = A("c")
a = C("a")

g.r = d
d.p = c
n.z = j
n.y = d
h.z = j
h.y = d
f.r = d
j.r = d
e.z = c
e.y = d
c.r = d
a.z = g
a.y = d
assert d.p.r.p.r.p.r.p.r.p.txt == "c"