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

class B:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

n = A("n")
l = B("l")
b = C("b")
f = D("f")

n.q = b
n.p = l
l.t = b
b.o = f
b.u = f
f.v = b
f.w = n
f.r = n
assert f.w.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.p: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

n = A("n")
l = B("l")
b = C("b")
f = D("f")

n.q = b
n.p = l
l.t = b
b.o = f
b.u = f
f.v = b
f.w = n
f.r = n
assert f.w.q.o.txt == "f"