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

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

l = A("l")
f = B("f")
h = A("h")
m = A("m")
b = B("b")

l.p = b
l.y = b
f.t = h
f.q = b
h.p = b
h.y = b
m.p = f
m.y = b
b.t = l
b.q = f
assert l.y.q.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.y: B = None
        self.txt = txt

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

l = A("l")
f = B("f")
h = A("h")
m = A("m")
b = B("b")

l.p = b
l.y = b
f.t = h
f.q = b
h.p = b
h.y = b
m.p = f
m.y = b
b.t = l
b.q = f
assert l.y.q.t.p.txt == "b"