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

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

a = A("a")
h = B("h")
f = B("f")
i = A("i")
g = A("g")
j = A("j")

a.q = j
a.t = g
h.r = f
h.w = f
f.r = h
f.w = h
i.q = g
i.t = g
g.q = a
g.t = a
j.q = g
j.t = a
assert j.t.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.t: A = None
        self.txt = txt

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

a = A("a")
h = B("h")
f = B("f")
i = A("i")
g = A("g")
j = A("j")

a.q = j
a.t = g
h.r = f
h.w = f
f.r = h
f.w = h
i.q = g
i.t = g
g.q = a
g.t = a
j.q = g
j.t = a
assert j.t.q.q.txt == "g"