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

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

h = A("h")
e = B("e")
g = C("g")
c = D("c")
k = D("k")

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

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

h = A("h")
e = B("e")
g = C("g")
c = D("c")
k = D("k")

h.r = g
h.z = g
e.u = h
g.o = k
c.x = h
c.w = g
k.x = h
k.w = g
assert g.o.x.z.o.x.txt == "h"