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

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

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

n = A("n")
h = B("h")
b = C("b")
j = A("j")
f = B("f")
d = C("d")

n.y = h
n.v = f
n.x = j
h.v = d
b.p = h
j.y = f
j.v = h
j.x = n
f.v = b
d.p = h
assert j.v.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.v: B = None
        self.x: A = None
        self.txt = txt

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

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

n = A("n")
h = B("h")
b = C("b")
j = A("j")
f = B("f")
d = C("d")

n.y = h
n.v = f
n.x = j
h.v = d
b.p = h
j.y = f
j.v = h
j.x = n
f.v = b
d.p = h
assert j.v.v.p.txt == "h"