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

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

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

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

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

n.s = m
i.x = b
i.r = c
e.s = c
j.q = b
b.x = i
b.r = n
g.s = m
c.s = m
m.s = g
assert m.s.s.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

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

n.s = m
i.x = b
i.r = c
e.s = c
j.q = b
b.x = i
b.r = n
g.s = m
c.s = m
m.s = g
assert m.s.s.s.s.s.s.s.s.txt == "m"