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

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

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

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

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

k.y = f
b.y = k
b.r = k
b.o = k
d.w = k
d.o = f
f.q = k
assert f.q.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

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

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

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

k.y = f
b.y = k
b.r = k
b.o = k
d.w = k
d.o = f
f.q = k
assert f.q.y.q.txt == "k"