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

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

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

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

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

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

b.t = n
a.o = i
a.p = b
f.t = m
i.o = l
i.p = j
g.o = l
g.p = j
n.o = i
n.p = j
m.o = n
m.p = b
j.t = n
l.o = m
l.p = f
assert i.o.p.t.o.p.t.o.o.p.txt == "f"