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

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

class C:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: F = None
        self.w: D = None
        self.txt = txt

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

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

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

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

d.q = b
d.p = e
a.o = d
e.r = a
e.u = f
e.w = h
h.u = a
h.v = e
b.x = a
f.z = h
n.z = h
assert f.z.u.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: E = None
        self.p: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: F = None
        self.w: D = None
        self.txt = txt

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

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

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

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

d.q = b
d.p = e
a.o = d
e.r = a
e.u = f
e.w = h
h.u = a
h.v = e
b.x = a
f.z = h
n.z = h
assert f.z.u.o.p.txt == "e"