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

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

j = A("j")
g = B("g")
b = A("b")
h = B("h")
e = A("e")
d = B("d")
a = A("a")
i = B("i")

j.u = a
g.p = h
b.u = a
h.p = g
e.u = a
d.p = h
a.u = j
i.p = g
assert g.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

j = A("j")
g = B("g")
b = A("b")
h = B("h")
e = A("e")
d = B("d")
a = A("a")
i = B("i")

j.u = a
g.p = h
b.u = a
h.p = g
e.u = a
d.p = h
a.u = j
i.p = g
assert g.p.p.p.p.p.p.txt == "g"