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

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

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

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

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

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

i.w = a
g.t = i
j.t = i
k.w = i
a.w = k
f.t = k
assert a.w.w.w.w.txt == "k"