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.w: B = None
        self.txt = txt

k = A("k")
b = B("b")
c = B("c")
e = B("e")
j = A("j")
f = B("f")
n = A("n")

k.q = n
k.r = j
b.w = c
c.w = b
e.w = f
j.q = k
j.r = k
f.w = e
n.q = j
n.r = k
assert c.w.w.w.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.w: B = None
        self.txt = txt

k = A("k")
b = B("b")
c = B("c")
e = B("e")
j = A("j")
f = B("f")
n = A("n")

k.q = n
k.r = j
b.w = c
c.w = b
e.w = f
j.q = k
j.r = k
f.w = e
n.q = j
n.r = k
assert c.w.w.w.txt == "b"