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

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

f = A("f")
h = B("h")
n = A("n")
k = A("k")
c = B("c")
i = B("i")

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

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

f = A("f")
h = B("h")
n = A("n")
k = A("k")
c = B("c")
i = B("i")

f.x = n
h.t = c
h.w = c
n.x = k
k.x = n
c.t = i
c.w = h
i.t = h
i.w = c
assert n.x.x.x.txt == "k"