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

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

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

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

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

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

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

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

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

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

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