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

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

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

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

c = A("c")
f = B("f")
g = C("g")
j = D("j")
m = B("m")
b = C("b")
i = A("i")

c.u = m
c.v = j
c.x = i
f.r = j
f.z = b
g.w = c
g.o = i
j.o = b
m.r = j
m.z = g
b.w = i
b.o = i
i.u = m
i.v = j
i.x = c
assert f.z.o.v.o.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.v: D = None
        self.x: A = None
        self.txt = txt

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

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

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

c = A("c")
f = B("f")
g = C("g")
j = D("j")
m = B("m")
b = C("b")
i = A("i")

c.u = m
c.v = j
c.x = i
f.r = j
f.z = b
g.w = c
g.o = i
j.o = b
m.r = j
m.z = g
b.w = i
b.o = i
i.u = m
i.v = j
i.x = c
assert f.z.o.v.o.txt == "b"