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

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

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

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

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

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

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

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

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

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

d.r = e
d.u = m
n.q = m
n.p = d
n.z = c
h.x = e
h.u = n
i.w = j
i.u = n
i.o = g
j.w = c
j.u = g
j.o = g
g.q = m
g.p = d
g.z = j
m.x = e
m.u = n
e.r = d
e.u = h
c.w = i
c.u = n
c.o = g
assert d.r.r.u.u.z.u.q.u.q.txt == "m"