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

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

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

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

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

b.o = a
a.u = c
g.o = a
g.w = a
c.p = a
assert g.w.u.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

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

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

b.o = a
a.u = c
g.o = a
g.w = a
c.p = a
assert g.w.u.p.u.txt == "c"