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

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

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

i = A("i")
n = B("n")
j = C("j")
b = A("b")
a = A("a")

i.p = a
i.v = b
n.r = a
j.z = n
j.w = a
b.p = i
b.v = i
a.p = b
a.v = i
assert n.r.p.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.v: A = None
        self.txt = txt

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

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

i = A("i")
n = B("n")
j = C("j")
b = A("b")
a = A("a")

i.p = a
i.v = b
n.r = a
j.z = n
j.w = a
b.p = i
b.v = i
a.p = b
a.v = i
assert n.r.p.v.p.txt == "a"