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

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

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

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

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

m.v = c
e.q = b
k.y = m
k.w = c
b.q = e
b.r = m
c.y = m
c.w = k
assert e.q.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

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

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

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

m.v = c
e.q = b
k.y = m
k.w = c
b.q = e
b.r = m
c.y = m
c.w = k
assert e.q.r.v.txt == "c"