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

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

g = A("g")
d = B("d")
b = A("b")
j = A("j")
m = A("m")
e = A("e")
c = B("c")
h = B("h")

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

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

g = A("g")
d = B("d")
b = A("b")
j = A("j")
m = A("m")
e = A("e")
c = B("c")
h = B("h")

g.p = d
d.u = e
b.p = c
j.p = d
m.p = d
e.p = h
c.u = b
h.u = g
assert m.p.u.p.u.p.u.p.txt == "h"