class A:
    def __init__(self, txt: str):
        self.q: D = 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.s: D = None
        self.x: C = None
        self.p: A = None
        self.q: B = None
        self.txt = txt

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

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

h.q = e
d.o = h
b.s = e
b.x = a
b.p = h
b.q = d
e.y = d
e.r = d
e.t = n
e.o = h
n.y = d
n.r = d
n.t = e
n.o = f
f.q = n
a.s = e
a.x = b
a.p = f
a.q = d
assert e.r.o.q.t.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = 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.s: D = None
        self.x: C = None
        self.p: A = None
        self.q: B = None
        self.txt = txt

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

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

h.q = e
d.o = h
b.s = e
b.x = a
b.p = h
b.q = d
e.y = d
e.r = d
e.t = n
e.o = h
n.y = d
n.r = d
n.t = e
n.o = f
f.q = n
a.s = e
a.x = b
a.p = f
a.q = d
assert e.r.o.q.t.y.txt == "d"