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

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

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

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

d = A("d")
m = B("m")
b = C("b")
l = D("l")
a = A("a")

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

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

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

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

d = A("d")
m = B("m")
b = C("b")
l = D("l")
a = A("a")

d.p = l
d.o = l
d.w = a
d.v = a
m.p = a
m.t = a
m.r = l
m.w = d
b.y = m
l.x = b
a.p = l
a.o = l
a.w = d
a.v = d
assert a.v.o.x.txt == "b"