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

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

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

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

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

a.x = l
a.q = l
a.y = d
j.y = a
j.r = e
f.x = l
f.y = i
f.p = j
f.s = j
c.x = j
c.s = d
c.w = l
d.y = a
d.r = b
i.x = d
i.s = j
i.w = a
b.x = l
b.y = i
b.p = j
b.s = j
m.x = l
m.y = c
m.p = j
m.s = d
e.x = l
e.y = c
e.p = j
e.s = j
l.x = a
l.q = a
l.y = d
assert m.y.w.x.y.y.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.y: B = None
        self.q: A = None
        self.txt = txt

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

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

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

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

a.x = l
a.q = l
a.y = d
j.y = a
j.r = e
f.x = l
f.y = i
f.p = j
f.s = j
c.x = j
c.s = d
c.w = l
d.y = a
d.r = b
i.x = d
i.s = j
i.w = a
b.x = l
b.y = i
b.p = j
b.s = j
m.x = l
m.y = c
m.p = j
m.s = d
e.x = l
e.y = c
e.p = j
e.s = j
l.x = a
l.q = a
l.y = d
assert m.y.w.x.y.y.x.y.txt == "d"