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

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

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

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

m = A("m")
n = B("n")
f = C("f")
g = D("g")
h = A("h")
b = D("b")
a = C("a")
j = D("j")

m.y = n
m.p = g
n.x = h
n.r = m
n.v = b
f.w = a
f.y = a
f.q = m
g.x = a
g.q = n
g.y = n
g.o = j
h.y = n
h.p = b
b.x = f
b.q = n
b.y = n
b.o = j
a.w = f
a.y = f
a.q = m
j.x = f
j.q = n
j.y = n
j.o = g
assert m.p.q.v.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.p: D = None
        self.txt = txt

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

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

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

m = A("m")
n = B("n")
f = C("f")
g = D("g")
h = A("h")
b = D("b")
a = C("a")
j = D("j")

m.y = n
m.p = g
n.x = h
n.r = m
n.v = b
f.w = a
f.y = a
f.q = m
g.x = a
g.q = n
g.y = n
g.o = j
h.y = n
h.p = b
b.x = f
b.q = n
b.y = n
b.o = j
a.w = f
a.y = f
a.q = m
j.x = f
j.q = n
j.y = n
j.o = g
assert m.p.q.v.y.x.txt == "h"