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

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

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

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

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

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

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

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

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

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

d.r = h
d.u = h
i.r = a
i.q = d
a.z = h
a.w = c
j.p = h
c.z = h
c.w = e
b.p = d
h.r = d
h.u = d
m.p = d
e.z = h
e.w = a
assert m.p.r.u.u.r.r.u.r.r.txt == "d"