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

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

i = A("i")
b = B("b")
a = C("a")
m = D("m")
g = E("g")
j = A("j")
l = A("l")
e = D("e")
k = A("k")

i.q = a
i.r = g
b.r = k
a.q = b
a.s = g
m.r = i
m.z = b
m.q = b
g.y = a
j.q = a
j.r = g
l.q = a
l.r = g
e.r = k
e.z = b
e.q = b
k.q = a
k.r = g
assert b.r.r.y.q.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.r: E = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

i = A("i")
b = B("b")
a = C("a")
m = D("m")
g = E("g")
j = A("j")
l = A("l")
e = D("e")
k = A("k")

i.q = a
i.r = g
b.r = k
a.q = b
a.s = g
m.r = i
m.z = b
m.q = b
g.y = a
j.q = a
j.r = g
l.q = a
l.r = g
e.r = k
e.z = b
e.q = b
k.q = a
k.r = g
assert b.r.r.y.q.r.r.txt == "g"