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

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

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

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

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

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

h.x = f
j.s = b
a.s = m
l.s = f
f.x = m
m.x = b
b.x = m
assert m.x.x.x.txt == "b"