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

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

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

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

m = A("m")
f = B("f")
n = C("n")
e = D("e")

m.q = f
f.q = e
n.s = e
e.w = n
e.q = m
e.p = m
assert n.s.w.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

m = A("m")
f = B("f")
n = C("n")
e = D("e")

m.q = f
f.q = e
n.s = e
e.w = n
e.q = m
e.p = m
assert n.s.w.s.w.txt == "n"