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

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

h = A("h")
i = B("i")
l = A("l")
g = B("g")
c = A("c")
n = A("n")
j = A("j")

h.p = c
i.w = n
l.p = j
g.w = l
c.p = n
n.p = l
j.p = h
assert j.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

h = A("h")
i = B("i")
l = A("l")
g = B("g")
c = A("c")
n = A("n")
j = A("j")

h.p = c
i.w = n
l.p = j
g.w = l
c.p = n
n.p = l
j.p = h
assert j.p.p.p.txt == "n"