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

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

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

f = A("f")
c = B("c")
a = C("a")
e = C("e")

f.u = e
c.r = e
c.p = a
a.w = f
a.p = f
a.v = c
e.w = f
e.p = f
e.v = c
assert a.v.p.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

f = A("f")
c = B("c")
a = C("a")
e = C("e")

f.u = e
c.r = e
c.p = a
a.w = f
a.p = f
a.v = c
e.w = f
e.p = f
e.v = c
assert a.v.p.v.r.txt == "e"