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

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

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

class D:
    def __init__(self, txt: str):
        self.p: C = None
        self.t: C = None
        self.q: D = None
        self.s: D = None
        self.txt = txt

l = A("l")
n = B("n")
e = C("e")
i = D("i")
a = D("a")
m = A("m")
g = C("g")
f = A("f")
h = D("h")

l.r = m
n.w = h
n.x = l
e.o = n
e.r = a
e.z = h
i.p = e
i.t = e
i.q = a
i.s = h
a.p = e
a.t = g
a.q = h
a.s = h
m.r = l
g.o = n
g.r = i
g.z = i
f.r = m
h.p = e
h.t = e
h.q = a
h.s = i
assert l.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.p: C = None
        self.t: C = None
        self.q: D = None
        self.s: D = None
        self.txt = txt

l = A("l")
n = B("n")
e = C("e")
i = D("i")
a = D("a")
m = A("m")
g = C("g")
f = A("f")
h = D("h")

l.r = m
n.w = h
n.x = l
e.o = n
e.r = a
e.z = h
i.p = e
i.t = e
i.q = a
i.s = h
a.p = e
a.t = g
a.q = h
a.s = h
m.r = l
g.o = n
g.r = i
g.z = i
f.r = m
h.p = e
h.t = e
h.q = a
h.s = i
assert l.r.r.r.txt == "m"