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

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

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

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

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

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

n.t = f
m.p = l
d.p = n
j.p = i
g.p = n
l.t = m
b.p = n
h.p = n
i.t = b
f.p = l
assert i.t.p.t.txt == "f"