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

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

j = A("j")
i = B("i")
e = B("e")
g = B("g")
l = A("l")
d = B("d")
b = A("b")

j.q = i
j.u = g
i.r = j
i.v = b
e.r = l
e.v = j
g.r = b
g.v = j
l.q = g
l.u = e
d.r = b
d.v = j
b.q = g
b.u = g
assert i.r.u.r.u.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.u: B = None
        self.txt = txt

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

j = A("j")
i = B("i")
e = B("e")
g = B("g")
l = A("l")
d = B("d")
b = A("b")

j.q = i
j.u = g
i.r = j
i.v = b
e.r = l
e.v = j
g.r = b
g.v = j
l.q = g
l.u = e
d.r = b
d.v = j
b.q = g
b.u = g
assert i.r.u.r.u.r.q.txt == "g"