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

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

k = A("k")
c = B("c")
g = B("g")
i = A("i")

k.x = g
c.p = i
c.x = g
g.p = i
g.x = c
i.x = g
assert k.x.p.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.p: A = None
        self.x: B = None
        self.txt = txt

k = A("k")
c = B("c")
g = B("g")
i = A("i")

k.x = g
c.p = i
c.x = g
g.p = i
g.x = c
i.x = g
assert k.x.p.x.p.txt == "i"