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

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

f = A("f")
g = B("g")
e = A("e")
h = B("h")
l = B("l")
d = A("d")

f.y = e
g.p = l
e.y = d
h.p = l
l.p = h
d.y = e
assert g.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

f = A("f")
g = B("g")
e = A("e")
h = B("h")
l = B("l")
d = A("d")

f.y = e
g.p = l
e.y = d
h.p = l
l.p = h
d.y = e
assert g.p.p.p.txt == "l"