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

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

f = A("f")
n = B("n")
b = A("b")
a = A("a")
l = B("l")
h = A("h")
m = B("m")
k = A("k")
c = B("c")

f.r = b
n.w = l
n.s = f
b.r = k
a.r = k
l.w = m
l.s = k
h.r = f
m.w = c
m.s = f
k.r = a
c.w = l
c.s = a
assert b.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

f = A("f")
n = B("n")
b = A("b")
a = A("a")
l = B("l")
h = A("h")
m = B("m")
k = A("k")
c = B("c")

f.r = b
n.w = l
n.s = f
b.r = k
a.r = k
l.w = m
l.s = k
h.r = f
m.w = c
m.s = f
k.r = a
c.w = l
c.s = a
assert b.r.r.r.txt == "k"