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

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

j = A("j")
c = B("c")
m = A("m")
a = B("a")
g = A("g")
i = A("i")

j.p = c
c.y = i
c.x = g
m.p = c
a.y = j
a.x = j
g.p = c
i.p = c
assert m.p.y.p.x.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

j = A("j")
c = B("c")
m = A("m")
a = B("a")
g = A("g")
i = A("i")

j.p = c
c.y = i
c.x = g
m.p = c
a.y = j
a.x = j
g.p = c
i.p = c
assert m.p.y.p.x.p.x.txt == "g"