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

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

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

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

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

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

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

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

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

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

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