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

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

d = A("d")
a = B("a")
m = A("m")
g = B("g")
l = A("l")
h = A("h")
f = A("f")
c = B("c")

d.p = f
a.o = g
m.p = h
g.o = a
l.p = f
h.p = d
f.p = h
c.o = g
assert d.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

d = A("d")
a = B("a")
m = A("m")
g = B("g")
l = A("l")
h = A("h")
f = A("f")
c = B("c")

d.p = f
a.o = g
m.p = h
g.o = a
l.p = f
h.p = d
f.p = h
c.o = g
assert d.p.p.p.p.txt == "f"