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

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

g = A("g")
f = B("f")
k = B("k")
a = B("a")
j = A("j")
h = A("h")
l = B("l")
i = A("i")
m = B("m")
b = B("b")

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

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

g = A("g")
f = B("f")
k = B("k")
a = B("a")
j = A("j")
h = A("h")
l = B("l")
i = A("i")
m = B("m")
b = B("b")

g.p = h
f.x = g
k.x = h
a.x = i
j.p = i
h.p = j
l.x = i
i.p = h
m.x = h
b.x = g
assert b.x.p.p.p.p.p.p.txt == "i"