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

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

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

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

h = A("h")
n = B("n")
i = C("i")
k = D("k")

h.s = n
h.x = i
h.q = k
n.q = h
i.o = n
k.v = h
k.s = i
assert k.v.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.x: C = None
        self.q: D = None
        self.txt = txt

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

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

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

h = A("h")
n = B("n")
i = C("i")
k = D("k")

h.s = n
h.x = i
h.q = k
n.q = h
i.o = n
k.v = h
k.s = i
assert k.v.s.q.txt == "h"