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

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

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

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

i = A("i")
j = B("j")
b = C("b")
k = D("k")
m = C("m")
f = C("f")
e = B("e")
d = D("d")
l = D("l")
g = A("g")

i.p = g
i.r = g
i.w = j
i.q = k
j.p = e
j.y = k
j.z = b
b.q = l
b.p = i
k.t = e
k.x = e
k.w = i
m.q = d
m.p = g
f.q = l
f.p = g
e.p = j
e.y = k
e.z = m
d.t = e
d.x = e
d.w = i
l.t = j
l.x = j
l.w = i
g.p = i
g.r = i
g.w = j
g.q = l
assert g.q.w.r.w.z.q.w.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.r: A = None
        self.w: B = None
        self.q: D = None
        self.txt = txt

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

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

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

i = A("i")
j = B("j")
b = C("b")
k = D("k")
m = C("m")
f = C("f")
e = B("e")
d = D("d")
l = D("l")
g = A("g")

i.p = g
i.r = g
i.w = j
i.q = k
j.p = e
j.y = k
j.z = b
b.q = l
b.p = i
k.t = e
k.x = e
k.w = i
m.q = d
m.p = g
f.q = l
f.p = g
e.p = j
e.y = k
e.z = m
d.t = e
d.x = e
d.w = i
l.t = j
l.x = j
l.w = i
g.p = i
g.r = i
g.w = j
g.q = l
assert g.q.w.r.w.z.q.w.p.q.txt == "l"