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

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

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

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

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

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

g.r = l
g.w = l
l.o = b
l.p = g
b.s = d
d.x = b
d.p = b
d.w = l
d.y = l
d.q = l
n.x = g
a.x = g
assert b.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.w: B = None
        self.txt = txt

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

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

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

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

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

g.r = l
g.w = l
l.o = b
l.p = g
b.s = d
d.x = b
d.p = b
d.w = l
d.y = l
d.q = l
n.x = g
a.x = g
assert b.s.p.s.txt == "d"