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

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

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

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

h = A("h")
k = B("k")
e = C("e")
m = D("m")
n = A("n")

h.o = n
k.t = m
k.q = m
k.s = e
k.v = e
e.p = k
m.x = n
m.v = n
m.q = k
n.o = h
assert h.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

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

h = A("h")
k = B("k")
e = C("e")
m = D("m")
n = A("n")

h.o = n
k.t = m
k.q = m
k.s = e
k.v = e
e.p = k
m.x = n
m.v = n
m.q = k
n.o = h
assert h.o.o.o.txt == "n"