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

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

k = A("k")
i = B("i")
h = B("h")
g = A("g")
l = B("l")

k.r = g
k.x = h
i.y = l
h.y = l
g.r = k
g.x = h
l.y = h
assert k.r.x.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.x: B = None
        self.txt = txt

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

k = A("k")
i = B("i")
h = B("h")
g = A("g")
l = B("l")

k.r = g
k.x = h
i.y = l
h.y = l
g.r = k
g.x = h
l.y = h
assert k.r.x.y.y.y.txt == "l"