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

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

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

f = A("f")
k = B("k")
n = C("n")
m = B("m")
j = A("j")

f.v = j
f.o = m
f.p = m
k.w = m
k.r = n
n.p = k
m.w = k
m.r = n
j.v = f
j.o = k
j.p = m
assert j.o.w.w.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.o: B = None
        self.p: B = None
        self.txt = txt

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

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

f = A("f")
k = B("k")
n = C("n")
m = B("m")
j = A("j")

f.v = j
f.o = m
f.p = m
k.w = m
k.r = n
n.p = k
m.w = k
m.r = n
j.v = f
j.o = k
j.p = m
assert j.o.w.w.w.r.txt == "n"