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

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

b = A("b")
h = B("h")
n = B("n")
j = A("j")
g = B("g")

b.q = j
b.y = j
h.r = g
h.u = n
n.r = h
n.u = g
j.q = b
j.y = b
g.r = n
g.u = n
assert j.y.q.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.y: A = None
        self.txt = txt

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

b = A("b")
h = B("h")
n = B("n")
j = A("j")
g = B("g")

b.q = j
b.y = j
h.r = g
h.u = n
n.r = h
n.u = g
j.q = b
j.y = b
g.r = n
g.u = n
assert j.y.q.y.q.txt == "j"