class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.q: B = None
        self.u: B = 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.txt = txt

d = A("d")
h = B("h")
g = C("g")

d.p = h
d.q = h
d.u = h
h.o = g
g.w = h
assert h.o.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.q: B = None
        self.u: B = 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.txt = txt

d = A("d")
h = B("h")
g = C("g")

d.p = h
d.q = h
d.u = h
h.o = g
g.w = h
assert h.o.w.o.txt == "g"