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

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

g = A("g")
d = B("d")
l = A("l")
k = A("k")
e = B("e")
n = A("n")
j = B("j")

g.y = d
d.p = l
l.y = e
k.y = d
e.p = g
n.y = d
j.p = l
assert j.p.y.p.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

g = A("g")
d = B("d")
l = A("l")
k = A("k")
e = B("e")
n = A("n")
j = B("j")

g.y = d
d.p = l
l.y = e
k.y = d
e.p = g
n.y = d
j.p = l
assert j.p.y.p.y.p.txt == "l"