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

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

l = A("l")
m = B("m")
c = A("c")
j = B("j")
f = A("f")
a = A("a")

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

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

l = A("l")
m = B("m")
c = A("c")
j = B("j")
f = A("f")
a = A("a")

l.p = m
m.x = l
m.y = a
c.p = m
j.x = l
j.y = f
f.p = j
a.p = j
assert m.y.p.x.p.y.p.txt == "j"