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

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

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

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

j = A("j")
m = B("m")
l = C("l")
h = D("h")
a = C("a")
d = B("d")

j.x = h
j.q = l
m.w = l
l.y = j
h.y = m
h.s = j
a.y = j
d.w = l
assert a.y.q.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.q: C = None
        self.txt = txt

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

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

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

j = A("j")
m = B("m")
l = C("l")
h = D("h")
a = C("a")
d = B("d")

j.x = h
j.q = l
m.w = l
l.y = j
h.y = m
h.s = j
a.y = j
d.w = l
assert a.y.q.y.txt == "j"