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

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

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

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

i = A("i")
h = B("h")
c = C("c")
b = D("b")
a = B("a")
m = C("m")
j = D("j")

i.u = c
i.o = c
h.o = b
h.t = a
h.x = j
c.p = i
c.q = j
c.v = a
c.r = a
b.p = j
a.o = b
a.t = h
a.x = j
m.p = i
m.q = b
m.v = a
m.r = a
j.p = b
assert m.r.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.o: C = None
        self.txt = txt

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

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

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

i = A("i")
h = B("h")
c = C("c")
b = D("b")
a = B("a")
m = C("m")
j = D("j")

i.u = c
i.o = c
h.o = b
h.t = a
h.x = j
c.p = i
c.q = j
c.v = a
c.r = a
b.p = j
a.o = b
a.t = h
a.x = j
m.p = i
m.q = b
m.v = a
m.r = a
j.p = b
assert m.r.x.p.txt == "b"