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

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

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

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

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

d.y = j
d.z = a
a.x = i
g.w = l
g.y = d
g.x = a
i.q = a
i.r = a
i.x = g
j.y = d
j.z = a
l.w = g
l.y = d
l.x = a
assert l.x.x.q.x.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.z: B = None
        self.txt = txt

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

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

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

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

d.y = j
d.z = a
a.x = i
g.w = l
g.y = d
g.x = a
i.q = a
i.r = a
i.x = g
j.y = d
j.z = a
l.w = g
l.y = d
l.x = a
assert l.x.x.q.x.x.w.txt == "l"