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

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

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

class D:
    def __init__(self, txt: str):
        self.q: A = None
        self.o: C = None
        self.z: A = None
        self.t: B = None
        self.txt = txt

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

h.s = i
n.y = i
n.s = h
i.p = k
k.q = h
k.z = h
k.o = i
k.t = n
assert k.t.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.q: A = None
        self.o: C = None
        self.z: A = None
        self.t: B = None
        self.txt = txt

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

h.s = i
n.y = i
n.s = h
i.p = k
k.q = h
k.z = h
k.o = i
k.t = n
assert k.t.y.p.txt == "k"