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

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

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

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

d = A("d")
a = B("a")
e = C("e")
i = D("i")

d.q = e
a.x = e
a.q = e
a.p = d
a.v = i
e.u = d
e.o = i
i.o = a
i.u = e
i.q = d
assert a.p.q.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.x: C = None
        self.p: A = None
        self.q: C = None
        self.v: D = None
        self.txt = txt

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

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

d = A("d")
a = B("a")
e = C("e")
i = D("i")

d.q = e
a.x = e
a.q = e
a.p = d
a.v = i
e.u = d
e.o = i
i.o = a
i.u = e
i.q = d
assert a.p.q.u.q.txt == "e"