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

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

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

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

f = A("f")
m = B("m")
d = C("d")
c = D("c")

f.q = d
m.o = c
d.o = m
d.x = c
c.u = f
assert m.o.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

f = A("f")
m = B("m")
d = C("d")
c = D("c")

f.q = d
m.o = c
d.o = m
d.x = c
c.u = f
assert m.o.u.q.txt == "d"