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

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

m = A("m")
b = B("b")
i = A("i")
f = A("f")
k = A("k")
c = A("c")
d = B("d")

m.o = k
m.t = b
b.p = c
i.o = m
i.t = d
f.o = m
f.t = d
k.o = m
k.t = d
c.o = m
c.t = b
d.p = k
assert d.p.t.p.o.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.t: B = None
        self.txt = txt

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

m = A("m")
b = B("b")
i = A("i")
f = A("f")
k = A("k")
c = A("c")
d = B("d")

m.o = k
m.t = b
b.p = c
i.o = m
i.t = d
f.o = m
f.t = d
k.o = m
k.t = d
c.o = m
c.t = b
d.p = k
assert d.p.t.p.o.t.p.txt == "c"