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

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

m = A("m")
a = B("a")
g = A("g")
k = B("k")

m.y = g
m.p = a
a.r = g
a.u = k
g.y = m
g.p = a
k.r = g
k.u = a
assert m.y.p.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.p: B = None
        self.txt = txt

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

m = A("m")
a = B("a")
g = A("g")
k = B("k")

m.y = g
m.p = a
a.r = g
a.u = k
g.y = m
g.p = a
k.r = g
k.u = a
assert m.y.p.r.p.txt == "a"