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

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

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

d = A("d")
n = B("n")
e = C("e")
l = A("l")
g = B("g")
j = A("j")
c = C("c")
h = B("h")
b = C("b")

d.p = n
n.v = g
n.q = e
e.r = b
e.y = l
l.p = n
g.v = h
g.q = b
j.p = g
c.r = b
c.y = j
h.v = n
h.q = b
b.r = e
b.y = d
assert b.r.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

d = A("d")
n = B("n")
e = C("e")
l = A("l")
g = B("g")
j = A("j")
c = C("c")
h = B("h")
b = C("b")

d.p = n
n.v = g
n.q = e
e.r = b
e.y = l
l.p = n
g.v = h
g.q = b
j.p = g
c.r = b
c.y = j
h.v = n
h.q = b
b.r = e
b.y = d
assert b.r.y.p.txt == "n"