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

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

k = A("k")
d = B("d")
a = B("a")
g = B("g")
l = A("l")

k.x = a
d.x = l
d.p = a
a.x = k
a.p = d
g.x = l
g.p = a
l.x = g
assert g.x.x.x.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

k = A("k")
d = B("d")
a = B("a")
g = B("g")
l = A("l")

k.x = a
d.x = l
d.p = a
a.x = k
a.p = d
g.x = l
g.p = a
l.x = g
assert g.x.x.x.x.p.txt == "a"