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

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

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

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

d = A("d")
j = B("j")
n = C("n")
c = D("c")
a = C("a")
e = A("e")

d.v = e
d.r = j
j.w = n
j.r = n
j.p = e
n.y = j
n.x = c
n.o = c
n.p = c
c.w = j
a.y = j
a.x = c
a.o = c
a.p = c
e.v = d
e.r = j
assert a.o.w.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.r: B = None
        self.txt = txt

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

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

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

d = A("d")
j = B("j")
n = C("n")
c = D("c")
a = C("a")
e = A("e")

d.v = e
d.r = j
j.w = n
j.r = n
j.p = e
n.y = j
n.x = c
n.o = c
n.p = c
c.w = j
a.y = j
a.x = c
a.o = c
a.p = c
e.v = d
e.r = j
assert a.o.w.r.p.txt == "c"