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

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

j = A("j")
k = B("k")
h = C("h")
n = D("n")
l = D("l")

j.s = k
j.r = h
k.x = l
h.y = n
h.q = j
n.t = l
n.s = l
n.r = k
n.q = j
l.t = n
l.s = n
l.r = k
l.q = j
assert h.q.s.x.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.r: C = 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.y: D = None
        self.q: A = None
        self.txt = txt

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

j = A("j")
k = B("k")
h = C("h")
n = D("n")
l = D("l")

j.s = k
j.r = h
k.x = l
h.y = n
h.q = j
n.t = l
n.s = l
n.r = k
n.q = j
l.t = n
l.s = n
l.r = k
l.q = j
assert h.q.s.x.r.x.txt == "l"