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

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

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

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

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

a.u = g
a.z = g
g.o = a
b.x = d
c.o = d
f.o = d
d.o = f
assert a.u.o.u.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.z: B = None
        self.txt = txt

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

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

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

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

a.u = g
a.z = g
g.o = a
b.x = d
c.o = d
f.o = d
d.o = f
assert a.u.o.u.o.z.txt == "g"