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

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

g = A("g")
a = B("a")
e = A("e")
i = A("i")
l = A("l")
j = B("j")
c = A("c")
n = A("n")

g.q = c
g.r = n
a.s = i
a.z = n
e.q = l
e.r = c
i.q = g
i.r = n
l.q = i
l.r = e
j.s = e
j.z = n
c.q = g
c.r = i
n.q = c
n.r = c
assert i.r.r.q.q.r.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.r: A = None
        self.txt = txt

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

g = A("g")
a = B("a")
e = A("e")
i = A("i")
l = A("l")
j = B("j")
c = A("c")
n = A("n")

g.q = c
g.r = n
a.s = i
a.z = n
e.q = l
e.r = c
i.q = g
i.r = n
l.q = i
l.r = e
j.s = e
j.z = n
c.q = g
c.r = i
n.q = c
n.r = c
assert i.r.r.q.q.r.r.q.txt == "c"