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

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

j = A("j")
c = B("c")
a = B("a")
n = B("n")
b = A("b")
d = B("d")

j.r = b
j.q = b
c.y = j
c.s = d
a.y = j
a.s = n
n.y = b
n.s = a
b.r = j
b.q = j
d.y = b
d.s = n
assert b.q.r.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.q: A = None
        self.txt = txt

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

j = A("j")
c = B("c")
a = B("a")
n = B("n")
b = A("b")
d = B("d")

j.r = b
j.q = b
c.y = j
c.s = d
a.y = j
a.s = n
n.y = b
n.s = a
b.r = j
b.q = j
d.y = b
d.s = n
assert b.q.r.q.q.txt == "b"