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

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

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

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

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

b.x = g
b.t = c
d.p = b
g.y = m
g.z = d
g.w = b
c.o = m
c.u = g
c.q = g
c.v = g
h.x = g
h.t = c
f.p = b
m.o = c
m.u = g
m.q = g
m.v = g
assert m.u.z.p.x.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.t: D = None
        self.txt = txt

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

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

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

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

b.x = g
b.t = c
d.p = b
g.y = m
g.z = d
g.w = b
c.o = m
c.u = g
c.q = g
c.v = g
h.x = g
h.t = c
f.p = b
m.o = c
m.u = g
m.q = g
m.v = g
assert m.u.z.p.x.z.p.txt == "b"