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

class B:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

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

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

m = A("m")
b = B("b")
i = C("i")
g = D("g")
n = A("n")

m.s = n
b.w = g
i.o = n
g.t = i
n.s = m
assert b.w.t.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

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

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

m = A("m")
b = B("b")
i = C("i")
g = D("g")
n = A("n")

m.s = n
b.w = g
i.o = n
g.t = i
n.s = m
assert b.w.t.o.s.txt == "m"