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

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

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

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

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

a.v = i
n.p = b
n.w = a
i.w = b
i.r = b
b.q = i
b.z = n
assert i.r.q.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

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

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

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

a.v = i
n.p = b
n.w = a
i.w = b
i.r = b
b.q = i
b.z = n
assert i.r.q.w.q.txt == "i"