class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.s: B = None
        self.r: D = 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.o: D = None
        self.v: B = None
        self.r: D = None
        self.txt = txt

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

k = A("k")
b = B("b")
f = C("f")
h = D("h")

k.w = f
k.s = b
k.r = h
b.q = h
f.o = h
f.r = h
f.v = b
h.o = k
assert f.o.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.s: B = None
        self.r: D = 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.o: D = None
        self.v: B = None
        self.r: D = None
        self.txt = txt

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

k = A("k")
b = B("b")
f = C("f")
h = D("h")

k.w = f
k.s = b
k.r = h
b.q = h
f.o = h
f.r = h
f.v = b
h.o = k
assert f.o.o.w.txt == "f"