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

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

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

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

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

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

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

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

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

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

m.p = f
f.u = m
f.o = g
f.x = g
d.x = m
g.v = m
g.q = f
g.z = f
c.v = m
c.q = f
c.z = f
assert m.p.x.v.p.u.txt == "m"