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.u: A = None
        self.txt = txt

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

e = A("e")
k = B("k")
j = C("j")
d = A("d")
g = A("g")
h = C("h")
n = B("n")

e.p = j
k.y = h
k.u = g
j.q = n
d.p = h
g.p = j
h.q = k
n.y = j
n.u = g
assert d.p.q.u.p.q.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.u: A = None
        self.txt = txt

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

e = A("e")
k = B("k")
j = C("j")
d = A("d")
g = A("g")
h = C("h")
n = B("n")

e.p = j
k.y = h
k.u = g
j.q = n
d.p = h
g.p = j
h.q = k
n.y = j
n.u = g
assert d.p.q.u.p.q.txt == "n"