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

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

f = A("f")
l = B("l")
b = B("b")
m = B("m")
i = A("i")
n = A("n")
d = A("d")
a = A("a")

f.p = m
l.p = d
l.q = m
b.p = d
b.q = m
m.p = a
m.q = b
i.p = l
n.p = l
d.p = l
a.p = l
assert f.p.q.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

f = A("f")
l = B("l")
b = B("b")
m = B("m")
i = A("i")
n = A("n")
d = A("d")
a = A("a")

f.p = m
l.p = d
l.q = m
b.p = d
b.q = m
m.p = a
m.q = b
i.p = l
n.p = l
d.p = l
a.p = l
assert f.p.q.p.p.p.txt == "d"