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

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

k = A("k")
g = B("g")
j = B("j")
l = A("l")

k.q = j
k.w = g
g.r = k
j.r = k
l.q = g
l.w = j
assert g.r.q.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.w: B = None
        self.txt = txt

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

k = A("k")
g = B("g")
j = B("j")
l = A("l")

k.q = j
k.w = g
g.r = k
j.r = k
l.q = g
l.w = j
assert g.r.q.r.q.txt == "j"