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

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

a = A("a")
k = B("k")
g = A("g")
c = A("c")
l = A("l")
n = A("n")
m = B("m")
j = A("j")
h = A("h")

a.x = c
k.w = m
k.r = g
g.x = c
c.x = l
l.x = c
n.x = h
m.w = k
m.r = g
j.x = h
h.x = j
assert n.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.w: B = None
        self.r: A = None
        self.txt = txt

a = A("a")
k = B("k")
g = A("g")
c = A("c")
l = A("l")
n = A("n")
m = B("m")
j = A("j")
h = A("h")

a.x = c
k.w = m
k.r = g
g.x = c
c.x = l
l.x = c
n.x = h
m.w = k
m.r = g
j.x = h
h.x = j
assert n.x.x.x.txt == "h"