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

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

c = A("c")
n = B("n")
i = A("i")
a = B("a")
f = A("f")
l = B("l")
g = A("g")

c.x = n
c.w = g
n.t = c
i.x = l
i.w = f
a.t = g
f.x = l
f.w = i
l.t = f
g.x = a
g.w = i
assert f.w.w.w.x.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.w: A = None
        self.txt = txt

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

c = A("c")
n = B("n")
i = A("i")
a = B("a")
f = A("f")
l = B("l")
g = A("g")

c.x = n
c.w = g
n.t = c
i.x = l
i.w = f
a.t = g
f.x = l
f.w = i
l.t = f
g.x = a
g.w = i
assert f.w.w.w.x.t.txt == "f"