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

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

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

j = A("j")
k = B("k")
g = C("g")
a = B("a")
e = B("e")

j.p = g
j.w = g
k.p = j
k.u = a
g.r = j
a.p = j
a.u = e
e.p = j
e.u = k
assert a.u.u.p.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.w: C = None
        self.txt = txt

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

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

j = A("j")
k = B("k")
g = C("g")
a = B("a")
e = B("e")

j.p = g
j.w = g
k.p = j
k.u = a
g.r = j
a.p = j
a.u = e
e.p = j
e.u = k
assert a.u.u.p.p.r.txt == "j"