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

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

b = A("b")
j = B("j")
k = A("k")
h = B("h")
g = B("g")
f = A("f")
n = A("n")
d = B("d")

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

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

b = A("b")
j = B("j")
k = A("k")
h = B("h")
g = B("g")
f = A("f")
n = A("n")
d = B("d")

b.x = n
j.p = d
k.x = f
h.p = j
g.p = j
f.x = k
n.x = k
d.p = h
assert j.p.p.p.p.p.p.p.txt == "d"