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

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

g = A("g")
b = B("b")
e = B("e")
l = A("l")
h = B("h")
m = A("m")
f = B("f")
k = A("k")

g.x = l
g.u = b
b.p = m
e.p = l
l.x = k
l.u = f
h.p = g
m.x = k
m.u = f
f.p = k
k.x = m
k.u = h
assert f.p.u.p.u.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.u: B = None
        self.txt = txt

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

g = A("g")
b = B("b")
e = B("e")
l = A("l")
h = B("h")
m = A("m")
f = B("f")
k = A("k")

g.x = l
g.u = b
b.p = m
e.p = l
l.x = k
l.u = f
h.p = g
m.x = k
m.u = f
f.p = k
k.x = m
k.u = h
assert f.p.u.p.u.p.x.txt == "k"