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

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

j = A("j")
l = B("l")
h = B("h")
n = B("n")
g = B("g")
f = A("f")
e = B("e")
k = B("k")

j.p = f
j.t = k
l.s = j
h.s = f
n.s = j
g.s = f
f.p = j
f.t = h
e.s = f
k.s = f
assert f.p.p.t.s.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.t: B = None
        self.txt = txt

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

j = A("j")
l = B("l")
h = B("h")
n = B("n")
g = B("g")
f = A("f")
e = B("e")
k = B("k")

j.p = f
j.t = k
l.s = j
h.s = f
n.s = j
g.s = f
f.p = j
f.t = h
e.s = f
k.s = f
assert f.p.p.t.s.p.p.txt == "f"