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

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

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

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

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

d.x = j
d.y = j
d.s = i
g.q = l
i.u = j
i.x = k
i.q = d
j.r = l
j.w = d
m.q = g
l.q = g
k.u = j
k.x = i
k.q = d
assert d.s.u.w.s.q.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.y: D = None
        self.s: C = None
        self.txt = txt

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

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

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

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

d.x = j
d.y = j
d.s = i
g.q = l
i.u = j
i.x = k
i.q = d
j.r = l
j.w = d
m.q = g
l.q = g
k.u = j
k.x = i
k.q = d
assert d.s.u.w.s.q.s.x.txt == "k"