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

class B:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

f = A("f")
a = B("a")
g = C("g")
b = D("b")

f.w = b
a.o = g
g.w = a
g.p = b
b.o = f
b.q = f
assert b.q.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

f = A("f")
a = B("a")
g = C("g")
b = D("b")

f.w = b
a.o = g
g.w = a
g.p = b
b.o = f
b.q = f
assert b.q.w.o.txt == "f"