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

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

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

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

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

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

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

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

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

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

i.q = f
i.x = l
c.p = a
c.x = e
c.z = m
a.r = c
a.q = i
f.w = c
m.q = e
m.x = l
h.q = e
h.x = l
g.r = c
g.q = m
e.w = c
l.r = c
l.q = i
assert a.q.q.w.x.w.x.w.x.txt == "e"