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

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

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

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

n = A("n")
g = B("g")
k = C("k")
l = D("l")
e = A("e")
b = D("b")
m = D("m")
c = B("c")
d = C("d")
h = B("h")

n.r = e
n.p = e
g.q = e
g.x = k
k.w = b
k.y = g
k.z = e
l.w = b
e.r = n
e.p = n
b.w = m
m.w = b
c.q = n
c.x = d
d.w = m
d.y = c
d.z = n
h.q = e
h.x = k
assert h.x.y.x.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.p: A = None
        self.txt = txt

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

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

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

n = A("n")
g = B("g")
k = C("k")
l = D("l")
e = A("e")
b = D("b")
m = D("m")
c = B("c")
d = C("d")
h = B("h")

n.r = e
n.p = e
g.q = e
g.x = k
k.w = b
k.y = g
k.z = e
l.w = b
e.r = n
e.p = n
b.w = m
m.w = b
c.q = n
c.x = d
d.w = m
d.y = c
d.z = n
h.q = e
h.x = k
assert h.x.y.x.z.p.txt == "n"