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

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

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

c = A("c")
j = B("j")
i = C("i")
h = B("h")
k = B("k")
g = C("g")

c.y = j
j.y = h
j.p = i
j.u = g
i.u = k
h.y = k
h.p = i
h.u = i
k.y = j
k.p = i
k.u = g
g.u = k
assert k.u.u.p.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

c = A("c")
j = B("j")
i = C("i")
h = B("h")
k = B("k")
g = C("g")

c.y = j
j.y = h
j.p = i
j.u = g
i.u = k
h.y = k
h.p = i
h.u = i
k.y = j
k.p = i
k.u = g
g.u = k
assert k.u.u.p.u.u.txt == "g"