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

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

class C:
    def __init__(self, txt: str):
        self.p: A = None
        self.o: D = None
        self.u: A = None
        self.txt = txt

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

c = A("c")
j = B("j")
m = C("m")
n = D("n")
e = C("e")
h = D("h")
d = C("d")
g = B("g")
k = A("k")

c.v = m
j.x = n
m.p = c
m.u = c
m.o = h
n.r = e
e.p = c
e.u = c
e.o = n
h.r = d
d.p = c
d.o = h
d.u = k
g.x = h
k.v = e
assert g.x.r.p.v.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.p: A = None
        self.o: D = None
        self.u: A = None
        self.txt = txt

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

c = A("c")
j = B("j")
m = C("m")
n = D("n")
e = C("e")
h = D("h")
d = C("d")
g = B("g")
k = A("k")

c.v = m
j.x = n
m.p = c
m.u = c
m.o = h
n.r = e
e.p = c
e.u = c
e.o = n
h.r = d
d.p = c
d.o = h
d.u = k
g.x = h
k.v = e
assert g.x.r.p.v.o.r.txt == "d"