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

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

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

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

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

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

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

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

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

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

d.q = i
d.x = h
i.y = g
i.s = k
a.w = j
j.y = a
j.s = k
g.q = i
g.x = d
h.q = i
h.x = g
k.w = j
assert g.x.x.x.q.s.w.txt == "j"