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

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

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

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

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

a.o = b
a.w = n
i.y = b
i.q = b
i.s = m
b.u = m
b.r = m
m.x = b
m.s = b
n.o = b
n.w = a
assert b.u.s.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.w: A = None
        self.txt = txt

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

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

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

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

a.o = b
a.w = n
i.y = b
i.q = b
i.s = m
b.u = m
b.r = m
m.x = b
m.s = b
n.o = b
n.w = a
assert b.u.s.r.x.txt == "b"