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

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

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

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

k = A("k")
l = B("l")
a = C("a")
b = D("b")

k.s = b
k.q = b
l.r = a
a.z = b
b.r = k
b.q = k
assert k.q.q.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.q: D = None
        self.txt = txt

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

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

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

k = A("k")
l = B("l")
a = C("a")
b = D("b")

k.s = b
k.q = b
l.r = a
a.z = b
b.r = k
b.q = k
assert k.q.q.s.q.txt == "k"