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

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

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

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

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

d = A("d")
n = B("n")
f = C("f")
g = D("g")
b = E("b")
h = A("h")
a = A("a")

d.z = n
d.x = f
d.u = h
n.p = f
f.q = n
g.q = n
b.x = h
h.z = n
h.x = f
h.u = d
a.z = n
a.x = f
a.u = h
assert a.x.q.p.q.p.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.x: C = None
        self.u: A = None
        self.txt = txt

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

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

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

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

d = A("d")
n = B("n")
f = C("f")
g = D("g")
b = E("b")
h = A("h")
a = A("a")

d.z = n
d.x = f
d.u = h
n.p = f
f.q = n
g.q = n
b.x = h
h.z = n
h.x = f
h.u = d
a.z = n
a.x = f
a.u = h
assert a.x.q.p.q.p.q.p.txt == "f"