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

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

c = A("c")
a = B("a")
h = B("h")
n = A("n")
f = A("f")
g = B("g")

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

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

c = A("c")
a = B("a")
h = B("h")
n = A("n")
f = A("f")
g = B("g")

c.t = f
a.x = f
h.x = f
n.t = c
f.t = c
g.x = f
assert f.t.t.t.t.t.txt == "c"