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

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

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

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

m = A("m")
b = B("b")
e = C("e")
c = D("c")

m.x = b
b.v = m
e.p = c
e.q = b
e.o = m
c.u = e
assert e.q.v.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

m = A("m")
b = B("b")
e = C("e")
c = D("c")

m.x = b
b.v = m
e.p = c
e.q = b
e.o = m
c.u = e
assert e.q.v.x.v.txt == "m"