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

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

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

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

l = A("l")
g = B("g")
e = C("e")
b = D("b")
a = B("a")

l.o = b
g.x = b
e.t = a
e.p = a
e.r = l
e.w = b
b.w = l
a.x = b
assert l.o.w.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

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

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

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

l = A("l")
g = B("g")
e = C("e")
b = D("b")
a = B("a")

l.o = b
g.x = b
e.t = a
e.p = a
e.r = l
e.w = b
b.w = l
a.x = b
assert l.o.w.o.w.txt == "l"