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

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

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

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

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

f.r = m
c.s = m
c.v = f
e.w = m
m.s = e
m.q = c
assert c.v.r.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

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

f.r = m
c.s = m
c.v = f
e.w = m
m.s = e
m.q = c
assert c.v.r.s.w.txt == "m"