class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.r: 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.q: C = None
        self.txt = txt

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

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

l.w = i
l.r = d
d.x = g
i.q = e
g.s = d
h.q = e
e.q = h
j.w = h
j.r = d
assert j.w.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.r: 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.q: C = None
        self.txt = txt

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

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

l.w = i
l.r = d
d.x = g
i.q = e
g.s = d
h.q = e
e.q = h
j.w = h
j.r = d
assert j.w.q.q.q.q.txt == "h"