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

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

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

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

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

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

i.t = j
j.q = a
a.t = j
f.q = i
assert j.q.t.q.t.txt == "j"