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

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

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

j = A("j")
h = B("h")
n = C("n")
i = B("i")
e = C("e")
f = C("f")

j.y = i
j.w = e
h.u = j
h.p = i
h.w = f
n.u = e
i.u = j
i.p = h
i.w = n
e.u = f
f.u = e
assert j.w.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.w: C = None
        self.txt = txt

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

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

j = A("j")
h = B("h")
n = C("n")
i = B("i")
e = C("e")
f = C("f")

j.y = i
j.w = e
h.u = j
h.p = i
h.w = f
n.u = e
i.u = j
i.p = h
i.w = n
e.u = f
f.u = e
assert j.w.u.u.u.u.u.txt == "f"