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

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

m = A("m")
i = B("i")
j = A("j")
a = B("a")
h = A("h")

m.p = a
i.t = a
j.p = a
a.t = i
h.p = i
assert j.p.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

m = A("m")
i = B("i")
j = A("j")
a = B("a")
h = A("h")

m.p = a
i.t = a
j.p = a
a.t = i
h.p = i
assert j.p.t.t.t.txt == "i"