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

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

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

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

j = A("j")
h = B("h")
g = C("g")
c = D("c")

j.r = g
j.p = g
h.w = j
h.r = j
h.u = j
g.o = c
c.x = g
c.p = g
assert h.u.r.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.p: C = None
        self.txt = txt

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

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

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

j = A("j")
h = B("h")
g = C("g")
c = D("c")

j.r = g
j.p = g
h.w = j
h.r = j
h.u = j
g.o = c
c.x = g
c.p = g
assert h.u.r.o.p.txt == "g"