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

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

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

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

a = A("a")
h = B("h")
f = C("f")
d = D("d")

a.o = h
a.p = f
a.x = f
h.r = a
f.s = a
f.w = a
f.q = d
f.r = h
d.o = h
assert f.w.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.p: C = None
        self.x: C = None
        self.txt = txt

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

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

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

a = A("a")
h = B("h")
f = C("f")
d = D("d")

a.o = h
a.p = f
a.x = f
h.r = a
f.s = a
f.w = a
f.q = d
f.r = h
d.o = h
assert f.w.p.q.txt == "d"